How to Build an MCP Tool for Claude Desktop

93.1K views
•
March 15, 2025
by
Matthew Berman
YouTube video player
How to Build an MCP Tool for Claude Desktop

TL;DR

Create a Python virtual environment, install the MCP library, define a tool with FastMCP, and run the server from a Python file. Then add the server command and absolute file path to Claude Desktop's JSON configuration, restart the application, confirm that the tool appears, and approve its use when prompted. The demonstrated tool counts three occurrences of the letter R in “strawberry.”

Transcript

let me show you how to set up a simple mCP server with a tool and get it running in Claude desktop if you're not familiar with what an mCP server is you can think of it like exposing a tool or set of tools to your AI assistant or agent so I created a tool that counts the number of RS in a given word and so here in Claude desktop I say use the count... Read More

Key Insights

  • An MCP server is a way to expose a tool or collection of tools to an AI assistant or agent. The count R example is intentionally simple, but the same basic structure can support weather tools, API wrappers, and other custom capabilities.
  • A dedicated Python environment is created inside the project folder before the server is written. The transcript shows separate activation commands for Windows and Mac, after which the MCP package is installed with pip so the project can import and use FastMCP.
  • FastMCP initializes the server with identifying and connection settings. The example supplies a server name, a local host address, a port, and a 30-second timeout, although the presenter notes that some of the extra settings were added for resilience and may not be necessary.
  • The tool decorator registers a Python function as an MCP tool. The demonstrated count function accepts a word as a string, produces an integer, converts the input to lowercase, and counts R characters, while additional checks and exception handling address invalid input or failures.
  • The server starts from the standard Python main entry point. It prints a startup message and calls the MCP run method, allowing the presenter to launch it from the terminal with the command “python server.py” and observe that the local process has started.
  • Claude Desktop discovers the tool through a JSON developer configuration file. The configuration defines the MCP server’s name, uses Python as the launch command, and provides arguments that include the absolute path to server.py, which the presenter identifies as the especially important part.
  • Claude Desktop asks for permission before using the local tool. The displayed choices include allowing it for the chat, allowing it once, or denying it, and the interface shows the input passed to the function and the output returned by the server.
  • An existing GitHub repository can provide additional MCP server examples. The referenced Awesome MCP Servers repository by AppCypher lists servers, their purposes, documentation, usage instructions, and connection guidance, reducing the need to design every possible integration from the beginning.

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: What is an MCP server used for?

An MCP server exposes a tool or set of tools to an AI assistant or agent. In the demonstration, it makes a Python function available inside Claude Desktop. That function receives a word, counts occurrences of the letter R, and returns the result, showing how an assistant can call external functionality during a conversation.

Q: How do you prepare a Python project for an MCP server?

Create a new folder with mkdir, move into it with cd, and create a Python virtual environment. Activate that environment using the Windows command shown in the transcript or the Mac source command, depending on the operating system. Then run “pip install mCP” to install the library required for writing the server.

Q: How do you define a tool with FastMCP?

Import FastMCP from the MCP server package, create a FastMCP server instance, and place the MCP tool decorator above a Python function. The example function accepts a word as a string and returns an integer. It converts the word to lowercase, counts the R characters, and includes checks and exception handling for robustness.

Q: How do you start the MCP server from the terminal?

Place the server startup call under the Python main entry-point condition, print a startup message if desired, and call the MCP run method. Save the implementation as server.py, then execute “python server.py” from the activated environment. The terminal should display startup information indicating that the local MCP server is running.

Q: How do you connect an MCP server to Claude Desktop?

Open Claude Desktop, go through File, Settings, and Developer, then select the option to edit the configuration. In the JSON file, define the MCP server, specify Python as the command, and include the absolute path to server.py in the arguments. The example also supplies host, port, and timeout information for added robustness.

Q: How can you confirm that Claude Desktop detected an MCP tool?

Open Claude Desktop’s developer settings and check whether the configured server appears with its command and arguments. In the conversation interface, a hammer icon indicates that tools are available. Selecting it should reveal the count R tool and its description, which says that it counts R letters in a given word.

Q: What happens when Claude Desktop invokes a local MCP tool?

Claude Desktop displays a permission dialogue before invoking the tool. The user can allow the tool for the current chat, allow it once, or deny access. After approval, the interface shows the input sent to the tool and its returned output. For “strawberry,” the demonstrated function returns the integer three.

Q: What should you try if Claude Desktop does not see the MCP server?

The presenter reports that Claude Desktop did not detect newly started MCP servers in his setup until he uninstalled and reinstalled the desktop application. He describes this as tedious and asks whether another approach exists, so the reinstall is presented as his observed workaround rather than a broadly established requirement for every setup.

Summary & Key Takeaways

  • An MCP server exposes one or more tools to an AI assistant or agent. The demonstration creates a local Python tool that accepts a word, converts it to lowercase, counts every occurrence of the letter R, and returns an integer. Claude Desktop calls the tool and reports three Rs in “strawberry.”

  • The setup begins by creating a project folder and Python virtual environment, activating that environment, and installing the MCP library. A server.py file imports FastMCP, initializes the local server, and registers the count function with the tool decorator. Optional signal handling, error handling, timeout settings, and status messages improve robustness.

  • Claude Desktop must be directed to the server through its developer configuration file. The JSON configuration identifies the MCP server, specifies Python as the command, and supplies the server file’s absolute path as an argument. Once detected, Claude displays the available tool and requests permission before invoking it in a conversation.


Read in Other Languages (beta)

Share This Summary 📚

Explore More Summaries from Matthew Berman 📚