first-mcp-server

21-aakash/first-mcp-server

3.2

If you are the rightful owner of first-mcp-server 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) provides a standardized, secure, and real-time communication interface for AI systems to connect with external tools, APIs, and data sources.

Tools
1
Resources
0
Prompts
0

What is MCP?

The Model Context Protocol (MCP) provides a standard, secure, real-time, two-way communication interface for AI systems to connect with external tools, API services, and data sources.

Unlike traditional API integration—which requires separate code, documentation, authentication methods, and ongoing maintenance—MCP offers a single, standardized way for AI models to interact with external systems. You write code once, and all AI systems can use it.

MCP Architecture

The MCP architecture consists of several key components that work together to enable seamless integration:

  1. Hosts: Applications (like Claude Desktop or AI-driven IDEs) that need access to external data or tools.
  2. Clients: Maintain dedicated, one-to-one connections with MCP servers.
  3. MCP Servers: Lightweight servers that expose specific functionalities via MCP, connecting to local or remote data sources.
  4. Local Data Sources: Files, databases, or services securely accessed by MCP servers.
  5. Remote Services: External internet-based APIs or services accessed by MCP servers.

How to Build an MCP Server

Install Libraries

pip install mcp mcp[cli]

Basic Example

from mcp.server.fastmcp import FastMCP
import math

# Instantiate an MCP server client
mcp = FastMCP("Hello World")

# Define tools

# Addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return int(a + b)

# Add a dynamic greeting resource
@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
    """Get a personalized greeting"""
    return f"Hello, {name}!"

# Execute and return the stdio output
if __name__ == "__main__":
    mcp.run(transport="stdio")

Connecting MCP Inspector to the Server

mcp dev server.py

How It Works

  • Import: The FastMCP server is imported from the MCP package, along with the math module.
  • Server Initialization: An MCP server client is created and named “Hello World”.
  • Tools & Resources: Tools are added using @mcp.tool() and resources using @mcp.resource(). These allow the server to perform operations and provide personalized greetings, exposing your data to LLMs in a controlled way.
  • Run: The MCP server is started with mcp.run(), enabling communication via standard input/output (stdio).

more: https://composio.dev/blog/mcp-server-step-by-step-guide-to-building-from-scrtch/