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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
<!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>