FastMCP Server is an implementation of the Model Context Protocol (MCP) that dynamically loads tools, resources, and prompts from directories. It provides an infrastructure for building applications that can interact with language models through a standardized protocol.
To use the FastMCP server, you'll need Python 3.10 or higher. Start by setting up your environment:
Clone the repository:
git clone https://github.com/yourusername/mcp-ynu.git
cd mcp-ynu
Install the required dependencies:
pip install fastmcp
Create an optional .env
file to configure the transport type:
MCP_TRANSPORT_TYPE=sse
To start the MCP server:
python main.py
The server will automatically load modules from the tools/
, resources/
, and prompts/
directories.
Tools are functions that can be called by the language model. Place your tool modules in the tools/
directory:
# tools/example.py
from mcp_server import mcp
import httpx
@mcp.tool()
def calculate_bmi(weight_kg: float, height_m: float) -> float:
"""Calculate BMI given weight in kg and height in meters"""
return weight_kg / (height_m**2)
@mcp.tool()
async def fetch_weather(city: str) -> str:
"""Fetch current weather for a city"""
async with httpx.AsyncClient() as client:
response = await client.get(f"https://api.weather.com/{city}")
return response.text
Resources provide data access through a URI-like interface. Place your resource modules in the resources/
directory:
# resources/example.py
from mcp_server import mcp
@mcp.resource("config://app")
def get_config() -> str:
"""Static configuration data"""
return "App configuration here"
@mcp.resource("users://{user_id}/profile")
def get_user_profile(user_id: str) -> str:
"""Dynamic user data"""
return f"Profile data for user {user_id}"
Prompts define interaction patterns with the language model. Place your prompt modules in the prompts/
directory:
# prompts/example.py
from mcp_server import mcp
from mcp.server.fastmcp.prompts import base
@mcp.prompt()
def review_code(code: str) -> str:
return f"Please review this code:\n\n{code}"
@mcp.prompt()
def debug_error(error: str) -> list[base.Message]:
return [
base.UserMessage("I'm seeing this error:"),
base.UserMessage(error),
base.AssistantMessage("I'll help debug that. What have you tried so far?"),
]
The MCP server comes with built-in support for debugging using the MCP Inspector tool:
.env
filepython main.py
npx @modelcontextprotocol/inspector
http://localhost:<mcp_server_port>/sse
python
with Arguments /path/to/main.py
To access the MCP instance in your code:
from mcp_server import mcp
# Now you can use mcp to register tools, resources, or prompts
@mcp.tool()
def my_custom_function():
# Function implementation
pass
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "ynu" '{"command":"python","args":["main.py"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"ynu": {
"command": "python",
"args": [
"main.py"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"ynu": {
"command": "python",
"args": [
"main.py"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect