mcp / getting-started.html
airabbitX's picture
Upload 9 files
3f22380 verified
raw
history blame
20.1 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Getting Started with MCP - Model Context Protocol</title>
<meta name="description" content="Learn how to get started with the Model Context Protocol (MCP) for connecting AI models to data sources and tools.">
<link rel="stylesheet" href="css/styles.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
</head>
<body>
<header>
<div class="container header-container">
<a href="index.html" class="logo">MCP<span>Hub</span></a>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="architecture.html">Architecture</a></li>
<li><a href="benefits.html">Benefits</a></li>
<li><a href="ecosystem.html">Ecosystem</a></li>
<li><a href="getting-started.html">Get Started</a></li>
<li><a href="faq.html">FAQ</a></li>
</ul>
</nav>
</div>
</header>
<section class="hero">
<div class="container">
<h1>Getting Started with MCP</h1>
<p>Begin your journey with the Model Context Protocol</p>
</div>
</section>
<main class="container">
<section>
<h2>Introduction</h2>
<p>
This guide will help you get started with the Model Context Protocol (MCP), whether you're building an AI application that needs to connect to external data sources or creating an MCP server to expose your data and tools to AI models.
</p>
<p>
We'll cover the basics of setting up both MCP clients and servers, with examples in different programming languages.
</p>
</section>
<section>
<h2>Prerequisites</h2>
<p>
Before you begin, make sure you have the following:
</p>
<ul style="margin-left: 2rem; margin-bottom: 1.5rem;">
<li>
<strong>Development Environment:</strong> A suitable development environment for your chosen programming language (Node.js for JavaScript/TypeScript, Python, Java, or .NET).
</li>
<li>
<strong>Basic Knowledge:</strong> Familiarity with your chosen programming language and basic concepts of AI and API integration.
</li>
<li>
<strong>Access to AI Models (for client development):</strong> Access to AI models that support MCP, such as Claude via Claude Desktop or the Claude API.
</li>
</ul>
</section>
<section>
<h2>Installation</h2>
<p>
The first step is to install the appropriate MCP SDK for your programming language:
</p>
<div class="card-container">
<div class="card">
<h3>TypeScript/JavaScript</h3>
<pre><code>npm install @modelcontextprotocol/client
npm install @modelcontextprotocol/server</code></pre>
</div>
<div class="card">
<h3>Python</h3>
<pre><code>pip install mcp-client
pip install mcp-server</code></pre>
</div>
<div class="card">
<h3>Java</h3>
<pre><code>// Add to your Maven pom.xml
<dependency>
<groupId>io.modelcontextprotocol</groupId>
<artifactId>mcp-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>io.modelcontextprotocol</groupId>
<artifactId>mcp-server</artifactId>
<version>1.0.0</version>
</dependency></code></pre>
</div>
<div class="card">
<h3>C#</h3>
<pre><code>dotnet add package ModelContextProtocol.Client
dotnet add package ModelContextProtocol.Server</code></pre>
</div>
</div>
</section>
<section>
<h2>Building an MCP Client</h2>
<p>
An MCP client is an application that connects to MCP servers to access data and tools. Here's how to create a basic MCP client:
</p>
<div class="two-column">
<div>
<h3>TypeScript/JavaScript Example</h3>
<pre><code>import { MCPClient } from '@modelcontextprotocol/client';
async function main() {
// Create an MCP client
const client = new MCPClient();
// Connect to an MCP server (e.g., filesystem server)
await client.connect({
transport: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '/path/to/directory']
});
// List available tools
const tools = await client.listTools();
console.log('Available tools:', tools);
// Call a tool
const result = await client.callTool({
name: 'readFile',
parameters: { path: 'example.txt' }
});
console.log('File contents:', result);
// Disconnect when done
await client.disconnect();
}
main().catch(console.error);</code></pre>
</div>
<div>
<h3>Python Example</h3>
<pre><code>from mcp_client import MCPClient
import asyncio
async def main():
# Create an MCP client
client = MCPClient()
# Connect to an MCP server (e.g., filesystem server)
await client.connect(
transport='stdio',
command='npx',
args=['-y', '@modelcontextprotocol/server-filesystem', '/path/to/directory']
)
# List available tools
tools = await client.list_tools()
print('Available tools:', tools)
# Call a tool
result = await client.call_tool(
name='readFile',
parameters={'path': 'example.txt'}
)
print('File contents:', result)
# Disconnect when done
await client.disconnect()
asyncio.run(main())</code></pre>
</div>
</div>
</section>
<section>
<h2>Building an MCP Server</h2>
<p>
An MCP server exposes data and tools to MCP clients. Here's how to create a basic MCP server:
</p>
<div class="two-column">
<div>
<h3>TypeScript/JavaScript Example</h3>
<pre><code>import { createServer, MCPTool } from '@modelcontextprotocol/server';
// Define a tool
const greetingTool: MCPTool = {
name: 'greeting',
description: 'Returns a greeting message',
parameters: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Name to greet'
}
},
required: ['name']
},
handler: async (params) => {
return `Hello, ${params.name}!`;
}
};
// Create an MCP server
const server = createServer({
name: 'greeting-server',
description: 'A server that provides greeting functionality',
version: '1.0.0',
tools: [greetingTool]
});
// Start the server
server.start();</code></pre>
</div>
<div>
<h3>Python Example</h3>
<pre><code>from mcp_server import create_server, MCPTool
# Define a tool
greeting_tool = MCPTool(
name='greeting',
description='Returns a greeting message',
parameters={
'type': 'object',
'properties': {
'name': {
'type': 'string',
'description': 'Name to greet'
}
},
'required': ['name']
}
)
# Define the handler function
async def greeting_handler(params):
return f"Hello, {params['name']}!"
# Attach the handler
greeting_tool.handler = greeting_handler
# Create an MCP server
server = create_server(
name='greeting-server',
description='A server that provides greeting functionality',
version='1.0.0',
tools=[greeting_tool]
)
# Start the server
server.start()</code></pre>
</div>
</div>
</section>
<section>
<h2>Using Existing MCP Servers</h2>
<p>
Instead of building your own MCP server from scratch, you can use existing MCP servers to add functionality to your applications:
</p>
<div class="card-container">
<div class="card">
<h3>Filesystem Server</h3>
<pre><code>// Install the filesystem server
npm install -g @modelcontextprotocol/server-filesystem
// Connect to the server in your client
await client.connect({
transport: 'stdio',
command: 'npx',
args: ['@modelcontextprotocol/server-filesystem', '/path/to/directory']
});</code></pre>
</div>
<div class="card">
<h3>Git Server</h3>
<pre><code>// Install the Git server
npm install -g @modelcontextprotocol/server-git
// Connect to the server in your client
await client.connect({
transport: 'stdio',
command: 'npx',
args: ['@modelcontextprotocol/server-git', '/path/to/repository']
});</code></pre>
</div>
<div class="card">
<h3>Postgres Server</h3>
<pre><code>// Install the Postgres server
npm install -g @modelcontextprotocol/server-postgres
// Connect to the server in your client
await client.connect({
transport: 'stdio',
command: 'npx',
args: ['@modelcontextprotocol/server-postgres', '--connection-string', 'postgresql://user:password@localhost:5432/database']
});</code></pre>
</div>
<div class="card">
<h3>Google Drive Server</h3>
<pre><code>// Install the Google Drive server
npm install -g @modelcontextprotocol/server-google-drive
// Connect to the server in your client
await client.connect({
transport: 'stdio',
command: 'npx',
args: ['@modelcontextprotocol/server-google-drive', '--credentials-file', '/path/to/credentials.json']
});</code></pre>
</div>
</div>
</section>
<section>
<h2>Connecting Claude to MCP Servers</h2>
<p>
Claude can connect to MCP servers through various interfaces, including Claude Desktop and the Claude API. Here's how to use MCP with Claude:
</p>
<div class="two-column">
<div>
<h3>Claude Desktop</h3>
<p>
Claude Desktop provides a user-friendly interface for connecting Claude to MCP servers:
</p>
<ol style="margin-left: 2rem; margin-bottom: 1.5rem;">
<li>Install Claude Desktop from Anthropic's website.</li>
<li>Open Claude Desktop and start a conversation.</li>
<li>Click on the "Connect" button in the interface.</li>
<li>Select the MCP server you want to connect to (e.g., filesystem, Git).</li>
<li>Follow the prompts to configure the server connection.</li>
<li>Once connected, Claude can access the data and tools provided by the MCP server.</li>
</ol>
</div>
<div>
<h3>Claude API with MCP</h3>
<p>
For programmatic access, you can use the Claude API with MCP:
</p>
<pre><code>import { MCPClient } from '@modelcontextprotocol/client';
import { Claude } from '@anthropic-ai/sdk';
async function main() {
// Create an MCP client
const mcpClient = new MCPClient();
// Connect to an MCP server
await mcpClient.connect({
transport: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '/path/to/directory']
});
// List available tools
const tools = await mcpClient.listTools();
// Create a Claude client
const claude = new Claude({
apiKey: process.env.ANTHROPIC_API_KEY
});
// Send a message to Claude with MCP tools
const response = await claude.messages.create({
model: 'claude-3-opus-20240229',
max_tokens: 1024,
messages: [
{
role: 'user',
content: 'Please read the file example.txt and summarize its contents.'
}
],
tools: tools
});
console.log(response.content);
}
main().catch(console.error);</code></pre>
</div>
</div>
</section>
<section>
<h2>Common Use Cases</h2>
<p>
Here are some common use cases for MCP and examples of how to implement them:
</p>
<div class="card-container">
<div class="card">
<h3>Document Processing</h3>
<p>
Use MCP to enable AI models to read, analyze, and process documents:
</p>
<pre><code>// Connect to the filesystem server
await client.connect({
transport: 'stdio',
command: 'npx',
args: ['@modelcontextprotocol/server-filesystem', '/path/to/documents']
});
// Read a document
const content = await client.callTool({
name: 'readFile',
parameters: { path: 'report.txt' }
});</code></pre>
</div>
<div class="card">
<h3>Database Queries</h3>
<p>
Use MCP to enable AI models to query databases:
</p>
<pre><code>// Connect to the Postgres server
await client.connect({
transport: 'stdio',
command: 'npx',
args: ['@modelcontextprotocol/server-postgres', '--connection-string', 'postgresql://user:password@localhost:5432/database']
});
// Execute a query
const results = await client.callTool({
name: 'executeQuery',
parameters: { query: 'SELECT * FROM users LIMIT 10' }
});</code></pre>
</div>
<div class="card">
<h3>Code Repository Access</h3>
<p>
Use MCP to enable AI models to access code repositories:
</p>
<pre><code>// Connect to the Git server
await client.connect({
transport: 'stdio',
command: 'npx',
args: ['@modelcontextprotocol/server-git', '/path/to/repository']
});
// List files in the repository
const files = await client.callTool({
name: 'listFiles',
parameters: { path: '.' }
});</code></pre>
</div>
<div class="card">
<h3>Web Browsing</h3>
<p>
Use MCP to enable AI models to browse the web:
</p>
<pre><code>// Connect to the Puppeteer server
await client.connect({
transport: 'stdio',
command: 'npx',
args: ['@modelcontextprotocol/server-puppeteer']
});
// Navigate to a webpage
const content = await client.callTool({
name: 'getPageContent',
parameters: { url: 'https://example.com' }
});</code></pre>
</div>
</div>
</section>
<section>
<h2>Best Practices</h2>
<p>
Here are some best practices to follow when working with MCP:
</p>
<div class="two-column">
<div>
<h3>Security Considerations</h3>
<ul style="margin-left: 2rem; margin-bottom: 1.5rem;">
<li>
<strong>Limit Access:</strong> Configure MCP servers to access only the resources that are necessary for the application.
</li>
<li>
<strong>Validate Inputs:</strong> Implement proper input validation for tool parameters to prevent security vulnerabilities.
</li>
<li>
<strong>Use Local Transport:</strong> For sensitive operations, use stdio transport to ensure data doesn't leave the local machine.
</li>
<li>
<strong>Secure API Keys:</strong> Protect API keys and credentials used by MCP servers.
</li>
</ul>
</div>
<div>
<h3>Performance Optimization</h3>
<ul style="margin-left: 2rem; margin-bottom: 1.5rem;">
<li>
<strong>Cache Tool Lists:</strong> Cache the results of <code>listTools</code> calls to reduce latency.
</li>
<li>
<strong>Optimize Data Transfer:</strong> Transfer only the necessary data between clients and servers to minimize overhead.
</li>
<li>
<strong>Implement Pagination:</strong> For tools that return large amounts of data, implement pagination to avoid performance issues.
</li>
<li>
<strong>Use Efficient Serialization:</strong> Choose efficient serialization formats for data exchange between clients and servers.
</li>
</ul>
</div>
</div>
<div class="two-column" style="margin-top: 2rem;">
<div>
<h3>Tool Design</h3>
<ul style="margin-left: 2rem; margin-bottom: 1.5rem;">
<li>
<strong>Clear Descriptions:</strong> Provide clear and detailed descriptions for tools and parameters to help AI models understand how to use them.
</li>
<li>
<strong>Consistent Naming:</strong> Use consistent naming conventions for tools and parameters across your MCP servers.
</li>
<li>
<strong>Atomic Operations:</strong> Design tools to perform atomic operations that can be composed to achieve complex tasks.
</li>
<li>
<strong>Error Handling:</strong> Implement robust error handling to provide informative error messages when tools fail.
</li>
</ul>
</div>
<div>
<h3>Testing and Debugging</h3>
<ul style="margin-left: 2rem; margin-bottom: 1.5rem;">
<li>
<strong>Unit Testing:</strong> Write comprehensive unit tests for your MCP servers and tools.
</li>
<li>
<strong>Integration Testing:</strong> Test the interaction between your MCP clients and servers to ensure compatibility.
</li>
<li>
<strong>Logging:</strong> Implement detailed logging in your MCP servers to help debug issues.
</li>
<li>
<strong>Mocking:</strong> Use mock MCP servers for testing to isolate client code from external dependencies.
</li>
</ul>
</div>
</div>
</section>
<section>
<h2>Next Steps</h2>
<p>
Now that you've learned the basics of MCP, here are some next steps to explore:
</p>
<div class="card-container">
<div class="card">
<h3>Explore the Ecosystem</h3>
<p>
Check out the <a href="ecosystem.html">MCP Ecosystem</a> page to discover available MCP servers, tools, and resources.
</p>
</div>
<div class="card">
<h3>Dive into the Architecture</h3>
<p>
Learn more about the <a href="architecture.html">MCP Architecture</a> to understand the technical details of how MCP works.
</p>
</div>
<div class="card">
<h3>Join the Community</h3>
<p>
Join the MCP community forums to ask questions, share ideas, and collaborate with other developers.
</p>
</div>
<div class="card">
<h3>Build Your Own MCP Server</h3>
<p>
Create your own MCP server to expose your data and tools to AI models, and consider contributing it to the community.
</p>
</div>
</div>
</section>
</main>
<footer>
<div class="container footer-container">
<div>
<h4>MCP Resources</h4>
<ul>
<li><a href="https://modelcontextprotocol.io" target="_blank">Official Documentation</a></li>
<li><a href="https://github.com/modelcontextprotocol" target="_blank">GitHub Repository</a></li>
<li><a href="https://www.anthropic.com/news/model-context-protocol" target="_blank">Anthropic MCP Announcement</a></li>
</ul>
</div>
<div>
<h4>Learn More</h4>
<ul>
<li><a href="about.html">About MCP</a></li>
<li><a href="architecture.html">Architecture</a></li>
<li><a href="benefits.html">Benefits</a></li>
<li><a href="ecosystem.html">Ecosystem</a></li>
</ul>
</div>
<div>
<h4>Community</h4>
<ul>
<li><a href="https://github.com/modelcontextprotocol/discussions" target="_blank">Discussions</a></li>
<li><a href="https://github.com/modelcontextprotocol/community-servers" target="_blank">Community Servers</a></li>
</ul>
</div>
</div>
<div class="copyright container">
<p>&copy; 2025 MCP Information Hub. Model Context Protocol is an open source project developed by Anthropic, PBC.</p>
</div>
</footer>
<script src="js/main.js"></script>
</body>
</html>