Skip to content

Commit 402d2a8

Browse files
committed
Update docs and add E2E tests for MCP APIs
Assisted-by: Claude Opus 4.6 Generated-by: Cursor Signed-off-by: Maysun J Faisal <maysunaneek@gmail.com>
1 parent 2dbac37 commit 402d2a8

8 files changed

Lines changed: 939 additions & 7 deletions

File tree

docs/ARCHITECTURE.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ This section describes the major functional components that make up LCore. Each
108108
- **Lifecycle Management**:
109109
- **Startup**: Load configuration, initialize Llama Stack client, load MCP server configuration and register all defined servers with Llama Stack to build the tools list, establish database connections
110110
- **Shutdown**: Clean up A2A storage resources (database connections and other resources are cleaned up automatically by Python's context managers)
111-
- **Router Registration**: Mount all endpoint routers (query, conversation, model info, auth, metrics, A2A, feedback, admin, mcp_auth)
111+
- **Router Registration**: Mount all endpoint routers (query, conversation, model info, auth, metrics, A2A, feedback, admin, mcp_auth, mcp_servers)
112112

113113
**Note:** All configured MCP servers must be running and accessible at startup time for LCore to initialize successfully.
114114

@@ -207,6 +207,9 @@ The system defines 30+ actions that can be authorized. Examples (see `docs/auth.
207207
**Agent-to-Agent Protocol:**
208208
- `A2A_JSONRPC` - A2A protocol access
209209

210+
**MCP Server Management:**
211+
- `REGISTER_MCP_SERVER`, `LIST_MCP_SERVERS`, `DELETE_MCP_SERVER`
212+
210213
**Metadata Operations:**
211214
- `LIST_MODELS`, `LIST_SHIELDS`, `LIST_TOOLS`, `LIST_PROVIDERS`
212215

@@ -325,7 +328,7 @@ MCP servers are remote HTTP services that expose tools/capabilities to LLMs (e.g
325328

326329
**How It Works:**
327330

328-
1. **Configuration:** MCP servers are defined in the config file with name, URL, and authorization headers
331+
1. **Configuration:** MCP servers are defined in the config file with name, URL, and authorization headers. Servers can also be registered dynamically at runtime via `POST /v1/mcp-servers`.
329332
2. **Registration at Startup:** LCore tells Llama Stack about each MCP server by calling `toolgroups.register()` - this makes the MCP server's tools available in Llama Stack's tool registry
330333
3. **Query Processing:** When processing a query, LCore determines which tools to make available to the LLM and finalizes authorization headers (e.g., merging client-provided tokens with configured headers)
331334
4. **Tool Execution:** When the LLM calls a tool, Llama Stack routes the request to the appropriate MCP server URL with the finalized authorization headers
@@ -489,6 +492,11 @@ This section documents the REST API endpoints exposed by LCore for client intera
489492
- Returns MCP servers that accept client-provided authentication tokens
490493
- Includes header names that need to be provided via MCP-HEADERS
491494

495+
**MCP Server Management:**
496+
- `POST /v1/mcp-servers` - Register a new MCP server at runtime
497+
- `GET /v1/mcp-servers` - List all registered MCP servers (static and dynamic)
498+
- `DELETE /v1/mcp-servers/{name}` - Unregister a dynamically registered MCP server
499+
492500
**List Shields:** `GET /shields`
493501
- Returns available guardrails
494502

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Global service configuration.
175175
| llama_stack | | This section contains Llama Stack configuration. Lightspeed Core Stack service can call Llama Stack in library mode or in server mode. |
176176
| user_data_collection | | This section contains configuration for subsystem that collects user data(transcription history and feedbacks). |
177177
| database | | Configuration for database to store conversation IDs and other runtime data |
178-
| mcp_servers | array | MCP (Model Context Protocol) servers provide tools and capabilities to the AI agents. These are configured in this section. Only MCP servers defined in the lightspeed-stack.yaml configuration are available to the agents. Tools configured in the llama-stack run.yaml are not accessible to lightspeed-core agents. |
178+
| mcp_servers | array | MCP (Model Context Protocol) servers provide tools and capabilities to the AI agents. These are configured in this section. Servers can also be registered dynamically at runtime via the `POST /v1/mcp-servers` API endpoint. Only MCP servers defined in lightspeed-stack.yaml or registered via the API are available to the agents. Tools configured in the llama-stack run.yaml are not accessible to lightspeed-core agents. |
179179
| authentication | | Authentication configuration |
180180
| authorization | | Lightspeed Core Stack implements a modular authentication and authorization system with multiple authentication methods. Authorization is configurable through role-based access control. Authentication is handled through selectable modules configured via the module field in the authentication configuration. |
181181
| customization | | It is possible to customize Lightspeed Core Stack via this section. System prompt can be customized and also different parts of the service can be replaced by custom Python modules. |

docs/getting_started.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ mcp_servers:
240240
url: "http://localhost:3002"
241241
```
242242

243-
**Important**: Only MCP servers defined in the `lightspeed-stack.yaml` configuration are available to the AI agents. Tools configured in the llama-stack `run.yaml` are not accessible to LCS agents.
243+
**Important**: MCP servers defined in `lightspeed-stack.yaml` or registered dynamically via the API (see [Dynamic MCP Server Management](#dynamic-mcp-server-management-via-api)) are available to the AI agents. Tools configured in the llama-stack `run.yaml` are not accessible to LCS agents.
244244

245245
#### Step 3: Pass authentication or metadata via MCP headers (optional)
246246

@@ -255,4 +255,79 @@ curl -X POST "http://localhost:8080/v1/query" \
255255
```
256256

257257
#### Step 4: Verify connectivity
258-
After starting the MCP servers and updating `lightspeed-stack.yaml`, test by sending a prompt to the AI agent. LCS evaluates the prompt against available tools’ metadata, selects the appropriate tool, calls the corresponding MCP server, and uses the result to generate more accurate agent response.
258+
After starting the MCP servers and updating `lightspeed-stack.yaml`, test by sending a prompt to the AI agent. LCS evaluates the prompt against available tools' metadata, selects the appropriate tool, calls the corresponding MCP server, and uses the result to generate more accurate agent response.
259+
260+
### Dynamic MCP Server Management via API
261+
262+
In addition to static configuration in `lightspeed-stack.yaml`, MCP servers can be registered, listed, and removed at runtime through the REST API. This is useful for development, testing, or scenarios where MCP servers are provisioned dynamically.
263+
264+
#### Register an MCP server
265+
266+
```bash
267+
curl -X POST "http://localhost:8080/v1/mcp-servers" \
268+
-H "Content-Type: application/json" \
269+
-d '{
270+
"name": "my-dynamic-tools",
271+
"url": "http://localhost:9000/mcp",
272+
"provider_id": "model-context-protocol"
273+
}'
274+
```
275+
276+
Response (201 Created):
277+
```json
278+
{
279+
"name": "my-dynamic-tools",
280+
"url": "http://localhost:9000/mcp",
281+
"provider_id": "model-context-protocol",
282+
"message": "MCP server 'my-dynamic-tools' registered successfully"
283+
}
284+
```
285+
286+
Optional fields in the request body:
287+
- `authorization_headers` (object): Headers to send to the MCP server (e.g., `{"Authorization": "Bearer token123"}`).
288+
- `headers` (array): List of HTTP header names to forward from incoming requests to this MCP server.
289+
- `timeout` (integer): Request timeout in seconds.
290+
291+
#### List all MCP servers
292+
293+
```bash
294+
curl "http://localhost:8080/v1/mcp-servers"
295+
```
296+
297+
Response (200 OK):
298+
```json
299+
{
300+
"servers": [
301+
{
302+
"name": "filesystem-tools",
303+
"url": "http://localhost:3000",
304+
"provider_id": "model-context-protocol",
305+
"source": "config"
306+
},
307+
{
308+
"name": "my-dynamic-tools",
309+
"url": "http://localhost:9000/mcp",
310+
"provider_id": "model-context-protocol",
311+
"source": "api"
312+
}
313+
]
314+
}
315+
```
316+
317+
Each server has a `source` field indicating how it was registered: `"config"` for servers defined in `lightspeed-stack.yaml`, or `"api"` for servers registered via the REST API.
318+
319+
#### Delete a dynamically registered MCP server
320+
321+
```bash
322+
curl -X DELETE "http://localhost:8080/v1/mcp-servers/my-dynamic-tools"
323+
```
324+
325+
Response (200 OK):
326+
```json
327+
{
328+
"name": "my-dynamic-tools",
329+
"message": "MCP server 'my-dynamic-tools' unregistered successfully"
330+
}
331+
```
332+
333+
**Note:** Only dynamically registered servers (source `"api"`) can be deleted via the API. Attempting to delete a statically configured server returns 403 Forbidden. Dynamically registered servers do not persist across service restarts.

0 commit comments

Comments
 (0)