@@ -49,75 +49,78 @@ def weather_report(location: str) -> str:
4949# Run the server
5050if __name__ == " __main__" :
5151 mcp.run()
52+ ```
5253
5354Once you have your server implemented, you can start it by running the server script.
5455
5556``` bash
5657mcp dev server.py
5758```
5859
59- ```
60-
6160</hfoption >
6261<hfoption id = " javascript" >
6362
6463``` javascript
6564// index.mjs
66- import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
65+ import {
66+ McpServer ,
67+ ResourceTemplate ,
68+ } from " @modelcontextprotocol/sdk/server/mcp.js" ;
6769import { StdioServerTransport } from " @modelcontextprotocol/sdk/server/stdio.js" ;
6870import { z } from " zod" ;
6971
7072// Create an MCP server
7173const server = new McpServer ({
72- name: "Weather Service",
73- version: "1.0.0"
74+ name: " Weather Service" ,
75+ version: " 1.0.0" ,
7476});
7577
7678// Tool implementation
77- server.tool("get_weather",
78- { location: z.string() },
79- async ({ location }) => ({
80- content: [{
81- type: "text",
82- text: `Weather in ${location}: Sunny, 72°F`
83- }]
84- })
85- );
79+ server .tool (" get_weather" , { location: z .string () }, async ({ location }) => ({
80+ content: [
81+ {
82+ type: " text" ,
83+ text: ` Weather in ${ location} : Sunny, 72°F` ,
84+ },
85+ ],
86+ }));
8687
8788// Resource implementation
8889server .resource (
89- "weather",
90- new ResourceTemplate("weather://{location}", { list: undefined }),
91- async (uri, { location }) => ({
92- contents: [{
93- uri: uri.href,
94- text: `Weather data for ${location}: Sunny, 72°F`
95- }]
96- })
90+ " weather" ,
91+ new ResourceTemplate (" weather://{location}" , { list: undefined }),
92+ async (uri , { location }) => ({
93+ contents: [
94+ {
95+ uri: uri .href ,
96+ text: ` Weather data for ${ location} : Sunny, 72°F` ,
97+ },
98+ ],
99+ })
97100);
98101
99102// Prompt implementation
100103server .prompt (
101- "weather_report",
102- { location: z.string() },
103- async ({ location }) => ({
104- messages: [
105- {
106- role: "assistant",
107- content: {
108- type: "text",
109- text: "You are a weather reporter."
110- }
111- },
112- {
113- role: "user",
114- content: {
115- type: "text",
116- text: `Weather report for ${location}?`
117- }
118- }
119- ]
120- })
104+ " weather_report" ,
105+ { location: z .string () },
106+ async ({ location }) => ({
107+ messages: [
108+ {
109+ role: " assistant" ,
110+ content: {
111+ type: " text" ,
112+ text: " You are a weather reporter." ,
113+ },
114+ },
115+ {
116+ role: " user" ,
117+ content: {
118+ type: " text" ,
119+ text: ` Weather report for ${ location} ?` ,
120+ },
121+ },
122+ ],
123+ })
121124);
122125
123126// Run the server
@@ -156,16 +159,16 @@ You'll see the server's capabilities and the ability to call them via the UI.
156159
157160MCP is designed to be language-agnostic, and there are official SDKs available for several popular programming languages:
158161
159- | Language | Repository | Maintainer(s) | Status |
160- | ----------| ------------| ---------------| --------|
161- | TypeScript | [ github.com/modelcontextprotocol/typescript-sdk] ( https://github.com/modelcontextprotocol/typescript-sdk ) | Anthropic | Active |
162- | Python | [ github.com/modelcontextprotocol/python-sdk] ( https://github.com/modelcontextprotocol/python-sdk ) | Anthropic | Active |
163- | Java | [ github.com/modelcontextprotocol/java-sdk] ( https://github.com/modelcontextprotocol/java-sdk ) | Spring AI (VMware) | Active |
164- | Kotlin | [ github.com/modelcontextprotocol/kotlin-sdk] ( https://github.com/modelcontextprotocol/kotlin-sdk ) | JetBrains | Active |
165- | C# | [ github.com/modelcontextprotocol/csharp-sdk] ( https://github.com/modelcontextprotocol/csharp-sdk ) | Microsoft | Active (Preview) |
166- | Swift | [ github.com/modelcontextprotocol/swift-sdk] ( https://github.com/modelcontextprotocol/swift-sdk ) | loopwork-ai | Active |
167- | Rust | [ github.com/modelcontextprotocol/rust-sdk] ( https://github.com/modelcontextprotocol/rust-sdk ) | Anthropic/Community | Active |
168- | Dart | [ https://github.com/leehack/mcp_dart ] ( https://github.com/leehack/mcp_dart ) | Flutter Community | Active |
162+ | Language | Repository | Maintainer(s) | Status |
163+ | ---------- | -------------------------------------------------------------------------------------------------------- | ------------------- | ---------------- |
164+ | TypeScript | [ github.com/modelcontextprotocol/typescript-sdk] ( https://github.com/modelcontextprotocol/typescript-sdk ) | Anthropic | Active |
165+ | Python | [ github.com/modelcontextprotocol/python-sdk] ( https://github.com/modelcontextprotocol/python-sdk ) | Anthropic | Active |
166+ | Java | [ github.com/modelcontextprotocol/java-sdk] ( https://github.com/modelcontextprotocol/java-sdk ) | Spring AI (VMware) | Active |
167+ | Kotlin | [ github.com/modelcontextprotocol/kotlin-sdk] ( https://github.com/modelcontextprotocol/kotlin-sdk ) | JetBrains | Active |
168+ | C# | [ github.com/modelcontextprotocol/csharp-sdk] ( https://github.com/modelcontextprotocol/csharp-sdk ) | Microsoft | Active (Preview) |
169+ | Swift | [ github.com/modelcontextprotocol/swift-sdk] ( https://github.com/modelcontextprotocol/swift-sdk ) | loopwork-ai | Active |
170+ | Rust | [ github.com/modelcontextprotocol/rust-sdk] ( https://github.com/modelcontextprotocol/rust-sdk ) | Anthropic/Community | Active |
171+ | Dart | [ https://github.com/leehack/mcp_dart ] ( https://github.com/leehack/mcp_dart ) | Flutter Community | Active |
169172
170173These SDKs provide language-specific abstractions that simplify working with the MCP protocol, allowing you to focus on implementing the core logic of your servers or clients rather than dealing with low-level protocol details.
171174
0 commit comments