The Apollo MCP Server is a tool that exposes GraphQL operations as Model Context Protocol (MCP) tools. This integration allows you to leverage your GraphQL API within the MCP ecosystem, enabling more powerful interactions between your data and large language models.
To install the Apollo MCP Server, you can use npm or yarn:
# Using npm
npm install @apollo/mcp-server
# Using yarn
yarn add @apollo/mcp-server
Create a new file for your MCP server implementation:
// mcp-server.js
import { ApolloMCPServer } from '@apollo/mcp-server';
import { ApolloServer } from '@apollo/server';
// Create your Apollo Server with your GraphQL schema
const apolloServer = new ApolloServer({
typeDefs: `
type Query {
hello: String
}
`,
resolvers: {
Query: {
hello: () => 'Hello world!'
}
}
});
// Create the MCP Server
const mcpServer = new ApolloMCPServer({
apolloServer,
tools: [
// Define your MCP tools here
]
});
// Start the server
const start = async () => {
await mcpServer.start();
console.log('MCP Server is running');
};
start();
You can define MCP tools based on your GraphQL operations:
// Define tools based on GraphQL operations
const tools = [
{
name: 'getUser',
description: 'Get user information by ID',
operation: `
query GetUser($id: ID!) {
user(id: $id) {
id
name
email
}
}
`,
parameters: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'The ID of the user to fetch'
}
},
required: ['id']
}
}
]
To start your MCP server:
node mcp-server.js
By default, the server listens on port 3000. You can customize the port:
// Custom port configuration
const mcpServer = new ApolloMCPServer({
apolloServer,
tools,
port: 4000
});
To use your MCP server with LLM services, you'll need to provide the server URL to your LLM provider:
// Example of configuring an LLM client to use your MCP server
const llmClient = new SomeLLMClient({
model: "gpt-4",
mcpServers: ["http://localhost:3000/mcp"]
});
You can create more complex tools with nested parameters:
{
name: 'searchProducts',
description: 'Search for products with filters',
operation: `
query SearchProducts($query: String!, $filter: ProductFilterInput) {
searchProducts(query: $query, filter: $filter) {
id
name
price
description
}
}
`,
parameters: {
type: 'object',
properties: {
query: {
type: 'string',
description: 'Search query string'
},
filter: {
type: 'object',
properties: {
minPrice: {
type: 'number',
description: 'Minimum price filter'
},
maxPrice: {
type: 'number',
description: 'Maximum price filter'
},
category: {
type: 'string',
description: 'Product category'
}
}
}
},
required: ['query']
}
}
You can add authentication to your MCP server:
const mcpServer = new ApolloMCPServer({
apolloServer,
tools,
context: async ({ req }) => {
// Get auth token from request
const token = req.headers.authorization || '';
// Validate token and get user
const user = await validateToken(token);
return { user };
}
});
Add custom error handling to provide better feedback:
const mcpServer = new ApolloMCPServer({
apolloServer,
tools,
formatError: (error) => {
console.error('GraphQL error:', error);
return {
message: error.message,
code: error.extensions?.code || 'INTERNAL_SERVER_ERROR',
path: error.path
};
}
});
For more detailed information and advanced configurations, visit the official Apollo MCP Server documentation.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "apollo-mcp-server" '{"command":"npx","args":["-y","apollo-mcp-server"]}'
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": {
"apollo-mcp-server": {
"command": "npx",
"args": [
"-y",
"apollo-mcp-server"
]
}
}
}
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": {
"apollo-mcp-server": {
"command": "npx",
"args": [
"-y",
"apollo-mcp-server"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect