-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmcpserver.http
More file actions
167 lines (138 loc) · 4.15 KB
/
mcpserver.http
File metadata and controls
167 lines (138 loc) · 4.15 KB
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
### BuildWithAspire MCP Server (MCP Protocol over HTTP with Session Management)
### This server implements the Model Context Protocol (MCP) specification
### with Streamable HTTP transport and session management via Mcp-Session-Id header
### Base URL: Auto-assigned port (check Aspire dashboard or use http://localhost:5267)
@baseUrl = http://localhost:5267
### === Server Status and Health ===
### Health Check
GET {{baseUrl}}/health
### Debug Info (Session and Transport Information)
GET {{baseUrl}}/debug/info
### Debug Tools (List Available Tools)
GET {{baseUrl}}/debug/tools
### === MCP Protocol with Session Management ===
### The server uses Streamable HTTP transport with stateful sessions
### Session ID is returned in the Mcp-Session-Id header on first request
### Include the same header in subsequent requests to maintain session
### Step 1: Initialize Session (First Request)
### This creates a new session and returns Mcp-Session-Id header
POST {{baseUrl}}/
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": "1",
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {
"tools": {}
},
"clientInfo": {
"name": "VSCode HTTP Client",
"version": "1.0.0"
}
}
}
### Step 2: List Available Tools (Using Session ID from Step 1)
### IMPORTANT: Copy the Mcp-Session-Id from Step 1 response headers and use it here
POST {{baseUrl}}/
Content-Type: application/json
Mcp-Session-Id: <paste-session-id-here>
{
"jsonrpc": "2.0",
"id": "2",
"method": "tools/list",
"params": {}
}
### Step 3: Call Weather Tool - Current Weather (With Session ID)
POST {{baseUrl}}/
Content-Type: application/json
Mcp-Session-Id: <paste-session-id-here>
{
"jsonrpc": "2.0",
"id": "3",
"method": "tools/call",
"params": {
"name": "getCurrentWeather",
"arguments": {}
}
}
### Step 4: Call Weather Tool - Forecast (With Session ID)
POST {{baseUrl}}/
Content-Type: application/json
Mcp-Session-Id: <paste-session-id-here>
{
"jsonrpc": "2.0",
"id": "4",
"method": "tools/call",
"params": {
"name": "getWeatherForecast",
"arguments": {
"maxDays": 5
}
}
}
### Step 5: Call Temperature Conversion Tool (With Session ID)
POST {{baseUrl}}/
Content-Type: application/json
Mcp-Session-Id: <paste-session-id-here>
{
"jsonrpc": "2.0",
"id": "5",
"method": "tools/call",
"params": {
"name": "convertTemperature",
"arguments": {
"temperature": 25,
"fromUnit": "C"
}
}
}
### Step 6: Call System Info Tool (With Session ID)
POST {{baseUrl}}/
Content-Type: application/json
Mcp-Session-Id: <paste-session-id-here>
{
"jsonrpc": "2.0",
"id": "6",
"method": "tools/call",
"params": {
"name": "getSystemInfo",
"arguments": {}
}
}
### Step 7: Open SSE Stream for Notifications (Optional)
### This keeps the session active and receives server-to-client messages
GET {{baseUrl}}/
Mcp-Session-Id: <paste-session-id-here>
### Step 8: Close Session (Optional - or wait for idle timeout)
DELETE {{baseUrl}}/
Mcp-Session-Id: <paste-session-id-here>
### === Session Management Notes ===
### 1. The first POST request creates a new session and returns Mcp-Session-Id
### 2. Use the same Mcp-Session-Id header in all subsequent requests
### 3. Sessions timeout after 2 hours of inactivity
### 4. Max 10,000 idle sessions can be tracked simultaneously
### 5. Without session ID, each request creates a new session (not recommended)
### === Testing via API Service ===
### For easier testing without manual session management,
### use the API Service MCP endpoints (they handle sessions internally):
### Get Available Tools (via API Service)
GET http://localhost:5020/mcp/tools
### Call Weather Forecast (via API Service - camelCase tool name)
POST http://localhost:5020/mcp/call/getWeatherForecast
Content-Type: application/json
{
"maxDays": 5
}
### Call Current Weather (via API Service - camelCase tool name)
POST http://localhost:5020/mcp/call/getCurrentWeather
Content-Type: application/json
{}
### Call Random Number Tool (via API Service - camelCase tool name)
POST http://localhost:5020/mcp/call/generateRandomNumber
Content-Type: application/json
{
"min": 1,
"max": 100
}