Build an MCP server changeddocs/2026-07-28/develop/build-server
Nearest release: v2.1.328, published 4 hours after upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 18 Nov 2026 18:56 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 18 Nov 2026 19:07 UTC.
Upstream edited
Recorded here
Lines+44added
Lines−27removed
From line
128
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits12to this page, all time
The whole hunk
from line 128, old and new numbered
/
from line 128
128128>
129129> import httpx2
130130> from mcp.server import MCPServer
131> from mcp.server.mcpserver.exceptions import ToolError
131132>
132133> # Initialize MCPServer
133134> mcp = MCPServer("weather")
from line 150
149150> async def make_nws_request(url: str) -> dict[str, Any] | None:
150151> """Make a request to the NWS API with proper error handling."""
151152> headers = {"User-Agent": USER_AGENT, "Accept": "application/geo+json"}
152> async with httpx2.AsyncClient() as client:
153> async with httpx2.AsyncClient(follow_redirects=True) as client:
153154> try:
154155> response = await client.get(url, headers=headers, timeout=30.0)
155156> response.raise_for_status()
from line 183
182183> Args:
183184> state: Two-letter US state code (e.g. CA, NY)
184185> """
185> url = f"{NWS_API_BASE}/alerts/active/area/{state}"
186> url = f"{NWS_API_BASE}/alerts/active/area/{state.upper()}"
186187> data = await make_nws_request(url)
187188>
188189> if not data or "features" not in data:
189> return "Unable to fetch alerts or no alerts found."
190> raise ToolError("Unable to fetch alerts.")
190191>
191192> if not data["features"]:
192193> return "No active alerts for this state."
from line 209
208209> points_data = await make_nws_request(points_url)
209210>
210211> if not points_data:
211> return "Unable to fetch forecast data for this location."
212> raise ToolError("Unable to fetch forecast data for this location.")
212213>
213214> # Get the forecast URL from the points response
214215> forecast_url = points_data["properties"]["forecast"]
from line 216
215216> forecast_data = await make_nws_request(forecast_url)
216217>
217218> if not forecast_data:
218> return "Unable to fetch detailed forecast."
219> raise ToolError("Unable to fetch detailed forecast.")
219220>
220221> # Format the periods into a readable forecast
221222> periods = forecast_data["properties"]["periods"]
223> if not periods:
224> raise ToolError("No forecast periods available.")
225>
222226> forecasts = []
223227> for period in periods[:5]: # Only show next 5 periods
224228> forecast = f"""
from line 415
411415> "weather": "./build/index.js"
412416> },
413417> "scripts": {
414> "build": "tsc && chmod 755 build/index.js"
418> "build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\""
415419> },
416420> "files": ["build"]
417421> }
from line 558
554558> },
555559> async ({ state }) => {
556560> const stateCode = state.toUpperCase();
557> const alertsUrl = `${NWS_API_BASE}/alerts?area=${stateCode}`;
561> const alertsUrl = `${NWS_API_BASE}/alerts/active?area=${stateCode}`;
558562> const alertsData = await makeNWSRequest<AlertsResponse>(alertsUrl);
559563>
560564> if (!alertsData) {
from line 569
565569> text: "Failed to retrieve alerts data",
566570> },
567571> ],
572> isError: true,
568573> };
569574> }
570575>
from line 629
624629> text: `Failed to retrieve grid point data for coordinates: ${latitude}, ${longitude}. This location may not be supported by the NWS API (only US locations are supported).`,
625630> },
626631> ],
632> isError: true,
627633> };
628634> }
629635>
from line 642
636642> text: "Failed to get forecast URL from grid point data",
637643> },
638644> ],
645> isError: true,
639646> };
640647> }
641648>
from line 656
649656> text: "Failed to retrieve forecast data",
650657> },
651658> ],
659> isError: true,
652660> };
653661> }
654662>
from line 669
661669> text: "No forecast periods available",
662670> },
663671> ],
672> isError: true,
664673> };
665674> }
666675>
from line 677
668677> const formattedForecast = periods.map((period: ForecastPeriod) =>
669678> [
670679> `${period.name || "Unknown"}:`,
671> `Temperature: ${period.temperature || "Unknown"}°${period.temperatureUnit || "F"}`,
680> `Temperature: ${period.temperature ?? "Unknown"}°${period.temperatureUnit || "F"}`,
672681> `Wind: ${period.windSpeed || "Unknown"} ${period.windDirection || ""}`,
673682> `${period.shortForecast || "No forecast available"}`,
674683> "---",
from line 837
828837>
829838> ```groovy Gradle theme={null}
830839> dependencies {
831> implementation platform("org.springframework.ai:spring-ai-starter-mcp-server")
832> implementation platform("org.springframework:spring-web")
840> implementation "org.springframework.ai:spring-ai-starter-mcp-server"
841> implementation "org.springframework:spring-web"
833842> }
834843> ```
835844>
from line 931
922931> }
923932> ```
924933>
925> Uses the `MethodToolCallbackProvider` utils to convert the `@Tools` into actionable callbacks used by the MCP server.
934> Uses the `MethodToolCallbackProvider` utils to convert the `@Tool` methods into actionable callbacks used by the MCP server.
926935>
927936> ### Running the server
928937>
from line 994
985994> "spring-ai-mcp-weather": {
986995> "command": "java",
987996> "args": [
988> "-Dspring.ai.mcp.server.transport=STDIO",
997> "-Dspring.ai.mcp.server.stdio=true",
989998> "-jar",
990> "C:\\ABSOLUTE\\PATH\\TO\\PARENT\\FOLDER\\weather\\mcp-weather-stdio-server-0.0.1-SNAPSHOT.jar"
999> "C:\\ABSOLUTE\\PATH\\TO\\PARENT\\FOLDER\\mcp-weather-stdio-server-0.0.1-SNAPSHOT.jar"
9911000> ]
9921001> }
9931002> }
from line 1009
10001009>
10011010> This tells Claude for Desktop:
10021011>
1003> 1. There's an MCP server named "my-weather-server"
1004> 2. To launch it by running `java -jar /ABSOLUTE/PATH/TO/PARENT/FOLDER/mcp-weather-stdio-server-0.0.1-SNAPSHOT.jar`
1012> 1. There's an MCP server named "spring-ai-mcp-weather"
1013> 2. To launch it by running `java -Dspring.ai.mcp.server.stdio=true -jar /ABSOLUTE/PATH/TO/PARENT/FOLDER/mcp-weather-stdio-server-0.0.1-SNAPSHOT.jar`
10051014>
10061015> Save the file, and restart **Claude for Desktop**.
10071016>
from line 1022
10131022>
10141023> ```java theme={null}
10151024> var stdioParams = ServerParameters.builder("java")
1016> .args("-jar", "/ABSOLUTE/PATH/TO/PARENT/FOLDER/mcp-weather-stdio-server-0.0.1-SNAPSHOT.jar")
1025> .args("-Dspring.ai.mcp.server.stdio=true", "-jar", "/ABSOLUTE/PATH/TO/PARENT/FOLDER/mcp-weather-stdio-server-0.0.1-SNAPSHOT.jar")
10171026> .build();
10181027>
10191028> var stdioTransport = new StdioClientTransport(stdioParams, McpJsonDefaults.getMapper());
from line 1035
10261035>
10271036> CallToolResult weather = mcpClient.callTool(
10281037> new CallToolRequest("getWeatherForecastByLocation",
1029> Map.of("latitude", "47.6062", "longitude", "-122.3321")));
1038> Map.of("latitude", 47.6062, "longitude", -122.3321)));
10301039>
10311040> CallToolResult alert = mcpClient.callTool(
10321041> new CallToolRequest("getAlerts", Map.of("state", "NY")));
from line 1233
12241233>
12251234> // Extension function to fetch weather alerts for a given state
12261235> suspend fun HttpClient.getAlerts(state: String): List<String> {
1227> val alerts = this.get("/alerts/active/area/$state").body<AlertsResponse>()
1236> val alerts = this.get("/alerts/active/area/${state.uppercase()}").body<AlertsResponse>()
12281237> return alerts.features.map { feature ->
12291238> """
12301239> Event: ${feature.properties.event}
from line 1321
13121321> val state = request.arguments?.get("state")?.jsonPrimitive?.content
13131322> ?: return@addTool CallToolResult(
13141323> content = listOf(TextContent("The 'state' parameter is required.")),
1324> isError = true,
13151325> )
13161326>
13171327> val alerts = httpClient.getAlerts(state)
from line 1350
13401350> if (latitude == null || longitude == null) {
13411351> return@addTool CallToolResult(
13421352> content = listOf(TextContent("The 'latitude' and 'longitude' parameters are required.")),
1353> isError = true,
13431354> )
13441355> }
13451356>
from line 1455
14441455>
14451456> * C#
14461457> * LLMs like Claude
1447> * .NET 8 or higher
1458> * .NET 10 or higher
14481459>
14491460> ### Logging in MCP Servers
14501461>
from line 1471
14601471>
14611472> ### System requirements
14621473>
1463> * [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) or higher installed.
1474> * [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0) or higher installed.
14641475>
14651476> ### Set up your environment
14661477>
from line 1506
14951506>
14961507> ```bash theme={null}
14971508> # Add the Model Context Protocol SDK NuGet package
1498> dotnet add package ModelContextProtocol --prerelease
1509> dotnet add package ModelContextProtocol
14991510> # Add the .NET Hosting NuGet package
15001511> dotnet add package Microsoft.Extensions.Hosting
15011512> ```
from line 1583
15721583> HttpClient client,
15731584> [Description("The US state code to get alerts for.")] string state)
15741585> {
1575> using var jsonDocument = await client.ReadJsonDocumentAsync($"/alerts/active/area/{state}");
1586> using var jsonDocument = await client.ReadJsonDocumentAsync($"/alerts/active/area/{state.ToUpperInvariant()}");
15761587> var jsonElement = jsonDocument.RootElement;
15771588> var alerts = jsonElement.GetProperty("features").EnumerateArray();
15781589>
from line 1691
16801691> This tells Claude for Desktop:
16811692>
16821693> 1. There's an MCP server named "weather"
1683> 2. Launch it by running `dotnet run /ABSOLUTE/PATH/TO/PROJECT`
1684> Save the file, and restart **Claude for Desktop**.
1694> 2. To launch it by running `dotnet run --project /ABSOLUTE/PATH/TO/PROJECT --no-build`
1695>
1696> Save the file, and restart **Claude for Desktop**.
16851697
16861698> [tab] Ruby
16871699>
from line 2427
24152427> }
24162428> ```
24172429>
2418> `get_info` returns a `ServerConfig`. Setting `server_info` gives the server its own name and version in the `initialize` response.
2430> `get_info` returns a `ServerConfig`. Setting `server_info` makes the server report its own name and version instead of those of the `rmcp` crate.
24192431>
24202432> ### Running the server
24212433>
from line 2750
27382750> Content: []mcp.Content{
27392751> &mcp.TextContent{Text: "Unable to fetch forecast data for this location."},
27402752> },
2753> IsError: true,
27412754> }, nil, nil
27422755> }
27432756>
from line 2761
27482761> Content: []mcp.Content{
27492762> &mcp.TextContent{Text: "Unable to fetch forecast URL."},
27502763> },
2764> IsError: true,
27512765> }, nil, nil
27522766> }
27532767>
from line 2771
27572771> Content: []mcp.Content{
27582772> &mcp.TextContent{Text: "Unable to fetch detailed forecast."},
27592773> },
2774> IsError: true,
27602775> }, nil, nil
27612776> }
27622777>
from line 2782
27672782> Content: []mcp.Content{
27682783> &mcp.TextContent{Text: "No forecast periods available."},
27692784> },
2785> IsError: true,
27702786> }, nil, nil
27712787> }
27722788>
from line 2812
27962812> if err != nil {
27972813> return &mcp.CallToolResult{
27982814> Content: []mcp.Content{
2799> &mcp.TextContent{Text: "Unable to fetch alerts or no alerts found."},
2815> &mcp.TextContent{Text: "Unable to fetch alerts."},
28002816> },
2817> IsError: true,
28012818> }, nil, nil
28022819> }
28032820>
from line 2945
29282945
29292946
29302947
2931After clicking on the plus icon, hover over the "Connectors" menu. You should see the `weather` servers listed:
2948After clicking on the plus icon, hover over the "Connectors" menu. You should see your weather server listed:
29322949
29332950
29342951
No line in this hunk matches that.