Log client capabilities and extensions on initialize requests
Add INFO-level logging to both the stateful SHTTP handler and the stateless example-apps handler to show the full client capabilities sent during MCP initialization, including any extensions like io.modelcontextprotocol/ui. This helps verify that clients are correctly sending UI extension capabilities during the initialization handshake.
This commit is contained in:
parent
f48f411661
commit
94ffb7922c
2 changed files with 28 additions and 4 deletions
|
|
@ -16,6 +16,7 @@ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/
|
|||
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
||||
import { ITokenValidator } from '../../interfaces/auth-validator.js';
|
||||
import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';
|
||||
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
||||
|
||||
// Import createServer from each example package (compiled JS)
|
||||
// All packages are published on the public npm registry
|
||||
|
|
@ -115,6 +116,24 @@ export class ExampleAppsModule {
|
|||
}
|
||||
|
||||
try {
|
||||
// Log initialization requests to inspect client capabilities/extensions
|
||||
if (isInitializeRequest(req.body)) {
|
||||
const initParams = req.body?.params;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const capabilities = initParams?.capabilities as Record<string, any> | undefined;
|
||||
console.log(JSON.stringify({
|
||||
severity: 'INFO',
|
||||
message: `=== MCP INITIALIZE REQUEST (${slug}) ===`,
|
||||
timestamp: new Date().toISOString(),
|
||||
slug,
|
||||
clientInfo: initParams?.clientInfo,
|
||||
protocolVersion: initParams?.protocolVersion,
|
||||
capabilities,
|
||||
hasExtensions: !!capabilities?.extensions,
|
||||
extensions: capabilities?.extensions,
|
||||
}));
|
||||
}
|
||||
|
||||
// Create fresh server and transport for each request (stateless mode)
|
||||
const server = createServer();
|
||||
const transport = new StreamableHTTPServerTransport({
|
||||
|
|
|
|||
|
|
@ -105,11 +105,16 @@ export async function handleStreamableHTTP(req: Request, res: Response) {
|
|||
shttpTransport = await getShttpTransport(sessionId, onsessionclosed, isGetRequest);
|
||||
} else if (isInitializeRequest(req.body)) {
|
||||
// New initialization request - use JSON response mode
|
||||
logger.debug('Processing initialize request', {
|
||||
body: req.body,
|
||||
const initParams = req.body?.params;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const capabilities = initParams?.capabilities as Record<string, any> | undefined;
|
||||
logger.info('=== MCP INITIALIZE REQUEST ===', {
|
||||
userId,
|
||||
headerSessionId: sessionId, // This is the sessionId from header (should be undefined for init)
|
||||
isInitializeRequest: true
|
||||
clientInfo: initParams?.clientInfo,
|
||||
protocolVersion: initParams?.protocolVersion,
|
||||
capabilities,
|
||||
hasExtensions: !!capabilities?.extensions,
|
||||
extensions: capabilities?.extensions,
|
||||
});
|
||||
|
||||
const onsessioninitialized = async (sessionId: string) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue