This MCP Server implements the Model Context Protocol, enabling applications to request language model responses with the proper context, authentication, and model selection. It serves as a crucial bridge between your applications and various language models, providing a standardized way to interact with LLMs.
You can install the MCP Server directly from PyPI:
pip install mcp-server
Alternatively, you can install from source:
git clone https://github.com/mlc-ai/mcp-server.git
cd mcp-server
pip install -e .
Before running the server, you'll need to create a configuration file. The MCP server uses YAML for configuration.
Create a file named config.yaml
with the following structure:
models:
- name: my-model
engine: openai
model: gpt-3.5-turbo
api_key: ${OPENAI_API_KEY}
This minimal configuration:
For more complex setups, you can configure multiple models and engines:
models:
- name: gpt4
engine: openai
model: gpt-4
api_key: ${OPENAI_API_KEY}
- name: local-llama
engine: llama.cpp
model_path: /path/to/llama-model.gguf
- name: anthropic-claude
engine: anthropic
model: claude-2
api_key: ${ANTHROPIC_API_KEY}
To start the MCP server with your configuration:
mcp-server --config path/to/config.yaml
By default, the server runs on localhost:8000
. You can specify a different address:
mcp-server --config path/to/config.yaml --host 0.0.0.0 --port 9000
The server supports referencing environment variables in the configuration file using ${VARIABLE_NAME}
syntax. Set your API keys as environment variables before starting the server:
export OPENAI_API_KEY=your-api-key-here
export ANTHROPIC_API_KEY=your-anthropic-key-here
mcp-server --config config.yaml
The MCP server provides the following key endpoints:
POST /v1/models
: List available modelsPOST /v1/chat/completions
: Generate chat completionsPOST /v1/completions
: Generate text completionsTo generate a chat completion:
curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "my-model",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
]
}'
You can use OpenAI client libraries by pointing them to your MCP server:
from openai import OpenAI
client = OpenAI(
api_key="not-needed", # MCP server handles authentication
base_url="http://localhost:8000/v1"
)
response = client.chat.completions.create(
model="my-model",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
]
)
print(response.choices[0].message.content)
To enable debug logs for troubleshooting:
mcp-server --config config.yaml --log-level debug
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 > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
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 explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.