mcp-server-project

Mohit2497/mcp-server-project

3.2

If you are the rightful owner of mcp-server-project and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Model Context Protocol (MCP) server allows AI applications to extend their capabilities by connecting to custom tools and resources, enabling more dynamic interactions with the real world.

Tools
1
Resources
0
Prompts
0

MCP Server Tutorial

I've been playing around with AI assistants lately, and I came across something called the Model Context Protocol (MCP). It's pretty cool. I followed this MCP tutorial and decided to document my little adventure.

What I Learned About MCP

Basically, MCP lets you give your AI superpowers. Before, I thought of AI as a closed box. You ask it something, it answers. But with MCP, you can build a bridge between the AI and the real world. I learned that I can create my own "tools" that the AI can use to do stuff it normally can't.

The Main Ideas I Picked Up

  • MCP Server: This is the backend I built. It's where my custom tools live.
  • MCP Client: This is the AI app that talks to my server, like Claude Desktop.
  • Tools: These are just Python functions that the AI can call. I made a get_latest_news tool that grabs headlines from the web.
  • Resources & Prompts: I also found out I can give the AI access to files (resources) and even give it templates for its replies (prompts).

How I Got My Server Running

The tutorial was a great help, and it was easier than I thought. Here's what I did:

  1. Installed the necessary libraries:

    I put all the Python libraries I needed into a requirements.txt file:

    fastapi
    uvicorn
    python-dotenv
    httpx
    beautifulsoup4
    mcp
    

    Then, I just ran this command in my terminal:

    pip install -r requirements.txt
    
  2. Started the server:

    Once everything was installed, I just had to run my Python script:

    python main.py
    

    And that's it! The server is now ready to be connected to Claude Desktop.

A Peek Inside main.py

Curious about what the Python code is actually doing? Let's break it down.

The main.py file is the heart of the server. Here's a quick tour:

  1. Importing the good stuff: At the top, I'm importing all the libraries I need, like FastMCP for creating the server, httpx for making web requests, and BeautifulSoup for parsing HTML.

  2. Setting up the MCP server: This line creates a new MCP server and gives it a name:

    mcp = FastMCP("tech_news")
    
  3. Defining the get_latest_news tool: This is the main tool I created. It's a Python function that takes a news source as input (like "techcrunch" or "theverge") and returns the latest news from that site.

    The @mcp.tool() decorator is what tells the MCP server that this function is a tool that can be used by the AI.

  4. Fetching the news: The fetch_news function is a helper function that does the heavy lifting of fetching the news from the web. It uses httpx to get the HTML of the news site and BeautifulSoup to parse it and extract the text from the paragraphs.

  5. Running the server: This is the last part of the script. The if __name__ == "__main__": block makes sure that the server only runs when I run the script directly. The mcp.run(transport='stdio') line is what actually starts the server.

So, in a nutshell, main.py creates an MCP server with a single tool that can fetch news from the web. When the AI calls this tool, the server runs the get_latest_news function and returns the result to the AI. Pretty neat, right?

Connecting to Claude Desktop

This is where the magic happens! To connect my server to Claude Desktop, I had to do a little bit of configuration. Here's how I did it:

Just a heads-up: These are the steps that worked for me. Your mileage may vary.

  1. Finding the config file:

    In Claude Desktop, I went to the "Claude" menu, then "Settings...", and then to the "Developer" tab. There's a button there to "Edit Config". That opens up the claude_desktop_config.json file.

  2. Editing the config file:

    I replaced the content of the file with this JSON snippet:

    {
      "mcpServers": {
        "tech_news_server": {
          "command": "python",
          "args": [
            "main.py"
          ]
        }
      }
    }
    
  3. Restarting Claude Desktop:

    I saved the file and then completely quit and restarted Claude Desktop. This is important, otherwise the changes won't take effect.

  4. Checking the connection:

    After restarting, I saw a little hammer icon in the bottom right of the prompt input area. That's how I knew my server was connected! Now I can ask Claude to get the latest news, and it will use my custom tool to do it.

My Two Cents

This was a really fun project. It showed me that I can make my AI assistants a lot more powerful. If you want to try it yourself, you should definitely check out the tutorial that got me started:

MODEL CONTEXT PROTOCOL (MCP): AN END-TO-END TUTORIAL WITH HANDS-ON PROJECT WITH PYTHON