You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This directory contains a minimal FastMCP server example and a companion client. FastMCP demonstrates a tiny, runnable implementation of an MCP-compatible service (Model Context Protocol) intended for local testing and quick deployment to cloud platforms.
6
+
This directory contains a FastMCP weather server example and a companion client. The server provides real-time weather information and forecasts using the free Open-Meteo API. It demonstrates a practical implementation of an MCP-compatible service (Model Context Protocol) for weather data, intended for local testing and quick deployment to [IBM Cloud Code Engine](https://www.ibm.com/products/code-engine).
7
7
8
8

9
9
@@ -32,40 +32,84 @@ Why Code Engine?
32
32
-**Simple deployment**: Integrates with container registries and CI/CD pipelines.
33
33
-**Managed endpoint**: Provides a secure http endpoint with a managed certificate.
34
34
35
-
A very tiny MCP Server
36
-
----------------------
35
+
Weather MCP Server Features
36
+
---------------------------
37
+
38
+
The server provides three weather-related tools:
39
+
40
+
1.**search_location**: Search for locations by name to get coordinates
41
+
2.**get_current_weather**: Get current weather conditions for specific coordinates
42
+
3.**get_weather_forecast**: Get weather forecast for 1-16 days
37
43
38
44
The Python source code for the MCP server is located in [./server/main.py](./server/main.py):
39
45
40
46
```python
41
47
from typing import Any
42
48
from fastmcp import FastMCP
43
-
from art importtext2art
49
+
importweather_api
44
50
45
-
mcp = FastMCP("My FastMCP Server on Code Engine")
51
+
mcp = FastMCP("Weather MCP Server on Code Engine")
52
+
53
+
@mcp.tool
54
+
asyncdefsearch_location(query: str) -> str:
55
+
"""
56
+
Search for a location by name to get coordinates for weather queries.
57
+
58
+
Args:
59
+
query: The location name to search for (e.g., "London", "New York", "Tokyo")
60
+
61
+
Returns:
62
+
A formatted string with matching locations and their coordinates
63
+
"""
64
+
try:
65
+
data =await weather_api.search_location(query)
66
+
return weather_api.format_location_results(data)
67
+
exceptExceptionas e:
68
+
returnf"Error searching for location: {str(e)}"
46
69
47
70
@mcp.tool
48
-
defascii_art(input: str) -> str:
49
-
"""Take an arbitraty input and return it as an ASCII art banner"""
The `call_tool.sh` script provides a quick way to test your deployed MCP server directly from the command line. It demonstrates the complete MCP protocol flow:
146
+
The `call_tool.sh` script provides a quick way to test your deployed MCP server directly from the command line. It demonstrates the complete MCP protocol flow with weather data for Stuttgart:
103
147
104
148
1. Initializes an MCP session with the server
105
149
2. Lists all available tools
106
-
3. Calls the `ascii_art` tool with "Code Engine" as input
107
-
4. Displays the ASCII art output
150
+
3. Searches for Stuttgart location
151
+
4. Gets current weather for Stuttgart (coordinates: 48.7758, 9.1829)
152
+
5. Gets 7-day weather forecast for Stuttgart
108
153
109
154
Run the script from the `mcp_server_fastmcp` directory:
110
155
111
156
```bash
112
157
./call_tool.sh
113
158
```
114
159
115
-
The script will automatically connect to your deployed FastMCP application and execute a test call. You should see output similar to:
160
+
The script will automatically connect to your deployed FastMCP application and execute weather queries for Stuttgart. You should see output similar to:
116
161
117
162
```
118
163
FastMCP application is reachable under the following url:
@@ -122,16 +167,32 @@ initialize session
122
167
Session initialized: <session-id>
123
168
124
169
List tools
125
-
Call tool 'ascii_art' with input 'Code Engine'
126
170
127
-
. ___ __ ____ ____
128
-
./ __)/ \( \( __)
129
-
.( (__( O )) D ( ) _)
130
-
.\___)\\__/(____/(____)
131
-
.____ __ _ ___ __ __ _ ____
132
-
.( __)( ( \ / __)( )( ( \( __)
133
-
..) _) / /( (_ \ )( / / ) _)
134
-
.(____)\\_)__) \\___/(__)\\_)__)(____)
171
+
==========================================
172
+
WEATHER TOOLS DEMONSTRATION FOR STUTTGART
173
+
==========================================
174
+
175
+
1. Search for 'Stuttgart' location
176
+
Stuttgart, Baden-Württemberg, Germany (lat: 48.7758, lon: 9.1829)
177
+
178
+
2. Get current weather for Stuttgart
179
+
Current Weather:
180
+
Condition: Partly cloudy
181
+
Temperature: 15.2°C
182
+
Feels like: 14.8°C
183
+
Humidity: 65%
184
+
Wind Speed: 12.5 km/h
185
+
Precipitation: 0.0 mm
186
+
187
+
3. Get 7-day weather forecast for Stuttgart
188
+
Weather Forecast:
189
+
190
+
2026-03-20:
191
+
Condition: Partly cloudy
192
+
Temperature: 8.5°C - 16.2°C
193
+
Precipitation: 0.2 mm (probability: 20%)
194
+
Max Wind Speed: 18.5 km/h
195
+
...
135
196
136
197
SUCCESS
137
198
```
@@ -147,7 +208,7 @@ Example `claude_desktop_config.json` entry that point to your deployed applicati
147
208
```json
148
209
{
149
210
"mcpServer": {
150
-
"ASCII Art FastMCP (Code Engine)": {
211
+
"Weather FastMCP (Code Engine)": {
151
212
"command": "npx",
152
213
"args": [
153
214
"mcp-remote",
@@ -164,21 +225,20 @@ Save settings and restart Claude Desktop; the remote MCP server should appear as
164
225
165
226
You can now chat with the MCP Server, e.g.
166
227
167
-
**_"Create ASCII art for: Hello, World!"_**
228
+
**_"Get the current weather and forecast of New York using the tool deployed in Code Engine :-)"_**
168
229
169
-
Claude will detect the tool and call the `ascii_art` function, responding with ASCII art output for your input text.
230
+
Claude will detect the appropriate weather tools and call them to provide current weather conditions or forecasts for the requested locations.
170
231
171
232

172
233
173
-
Note, the LLM even detected the simplicity of our MCP Server.
174
-
175
234
Building and using the Python client
176
235
-----------------------------
177
-
The `client` directory contains a small Python client to exercise the server.
236
+
The `client` directory contains a small Python client to exercise the weather server.
178
237
179
238
1. Create a virtual environment and install dependencies:
180
239
181
240
```bash
241
+
cd client
182
242
python3 -m venv .venv
183
243
source .venv/bin/activate
184
244
pip install -r requirements.txt
@@ -192,8 +252,13 @@ Start the client by replacing the application URL from above as the `MCP_SERVER_
The client will demonstrate all three weather tools using Stuttgart as an example location:
256
+
- Search for Stuttgart location
257
+
- Get current weather for Stuttgart
258
+
- Get 7-day weather forecast for Stuttgart
259
+
195
260
3. Inspect and adapt
196
-
- Open `client.py` to find example calls. The client is intentionally minimal so you can adapt it to your tooling or CI.
261
+
- Open `client.py` to find example calls. The client demonstrates how to use all weather tools and can be adapted to query different locations or forecast periods.
0 commit comments