Spaces:
Paused
Paused
Upload folder using huggingface_hub (part 20)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/providers/proxyProvider.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/providers/proxyProvider.js +155 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/providers/proxyProvider.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/router.d.ts +101 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/router.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/router.js +118 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/router.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/types.d.ts +32 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/types.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/types.js +2 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/types.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.d.ts +38 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js +41 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.d.ts +45 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js +50 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.d.ts +196 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js +440 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.d.ts +364 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js +917 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/middleware/hostHeaderValidation.d.ts +32 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/middleware/hostHeaderValidation.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/middleware/hostHeaderValidation.js +76 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/middleware/hostHeaderValidation.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.d.ts +82 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js +165 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.d.ts +28 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js +75 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.d.ts +122 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.js +161 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.d.ts +268 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js +751 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.d.ts +84 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.d.ts.map +1 -0
- node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js +209 -0
node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/providers/proxyProvider.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"proxyProvider.d.ts","sourceRoot":"","sources":["../../../../../src/server/auth/providers/proxyProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACH,0BAA0B,EAE1B,2BAA2B,EAC3B,WAAW,EAEd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1E,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,MAAM,MAAM,cAAc,GAAG;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACvB;;OAEG;IACH,SAAS,EAAE,cAAc,CAAC;IAE1B;;OAEG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAExD;;OAEG;IACH,SAAS,EAAE,CAAC,QAAQ,EAA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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { OAuthClientInformationFullSchema, OAuthTokensSchema } from '../../../shared/auth.js';
|
| 2 |
+
import { ServerError } from '../errors.js';
|
| 3 |
+
/**
|
| 4 |
+
* Implements an OAuth server that proxies requests to another OAuth server.
|
| 5 |
+
*/
|
| 6 |
+
export class ProxyOAuthServerProvider {
|
| 7 |
+
constructor(options) {
|
| 8 |
+
this.skipLocalPkceValidation = true;
|
| 9 |
+
this._endpoints = options.endpoints;
|
| 10 |
+
this._verifyAccessToken = options.verifyAccessToken;
|
| 11 |
+
this._getClient = options.getClient;
|
| 12 |
+
this._fetch = options.fetch;
|
| 13 |
+
if (options.endpoints?.revocationUrl) {
|
| 14 |
+
this.revokeToken = async (client, request) => {
|
| 15 |
+
const revocationUrl = this._endpoints.revocationUrl;
|
| 16 |
+
if (!revocationUrl) {
|
| 17 |
+
throw new Error('No revocation endpoint configured');
|
| 18 |
+
}
|
| 19 |
+
const params = new URLSearchParams();
|
| 20 |
+
params.set('token', request.token);
|
| 21 |
+
params.set('client_id', client.client_id);
|
| 22 |
+
if (client.client_secret) {
|
| 23 |
+
params.set('client_secret', client.client_secret);
|
| 24 |
+
}
|
| 25 |
+
if (request.token_type_hint) {
|
| 26 |
+
params.set('token_type_hint', request.token_type_hint);
|
| 27 |
+
}
|
| 28 |
+
const response = await (this._fetch ?? fetch)(revocationUrl, {
|
| 29 |
+
method: 'POST',
|
| 30 |
+
headers: {
|
| 31 |
+
'Content-Type': 'application/x-www-form-urlencoded'
|
| 32 |
+
},
|
| 33 |
+
body: params.toString()
|
| 34 |
+
});
|
| 35 |
+
await response.body?.cancel();
|
| 36 |
+
if (!response.ok) {
|
| 37 |
+
throw new ServerError(`Token revocation failed: ${response.status}`);
|
| 38 |
+
}
|
| 39 |
+
};
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
get clientsStore() {
|
| 43 |
+
const registrationUrl = this._endpoints.registrationUrl;
|
| 44 |
+
return {
|
| 45 |
+
getClient: this._getClient,
|
| 46 |
+
...(registrationUrl && {
|
| 47 |
+
registerClient: async (client) => {
|
| 48 |
+
const response = await (this._fetch ?? fetch)(registrationUrl, {
|
| 49 |
+
method: 'POST',
|
| 50 |
+
headers: {
|
| 51 |
+
'Content-Type': 'application/json'
|
| 52 |
+
},
|
| 53 |
+
body: JSON.stringify(client)
|
| 54 |
+
});
|
| 55 |
+
if (!response.ok) {
|
| 56 |
+
await response.body?.cancel();
|
| 57 |
+
throw new ServerError(`Client registration failed: ${response.status}`);
|
| 58 |
+
}
|
| 59 |
+
const data = await response.json();
|
| 60 |
+
return OAuthClientInformationFullSchema.parse(data);
|
| 61 |
+
}
|
| 62 |
+
})
|
| 63 |
+
};
|
| 64 |
+
}
|
| 65 |
+
async authorize(client, params, res) {
|
| 66 |
+
// Start with required OAuth parameters
|
| 67 |
+
const targetUrl = new URL(this._endpoints.authorizationUrl);
|
| 68 |
+
const searchParams = new URLSearchParams({
|
| 69 |
+
client_id: client.client_id,
|
| 70 |
+
response_type: 'code',
|
| 71 |
+
redirect_uri: params.redirectUri,
|
| 72 |
+
code_challenge: params.codeChallenge,
|
| 73 |
+
code_challenge_method: 'S256'
|
| 74 |
+
});
|
| 75 |
+
// Add optional standard OAuth parameters
|
| 76 |
+
if (params.state)
|
| 77 |
+
searchParams.set('state', params.state);
|
| 78 |
+
if (params.scopes?.length)
|
| 79 |
+
searchParams.set('scope', params.scopes.join(' '));
|
| 80 |
+
if (params.resource)
|
| 81 |
+
searchParams.set('resource', params.resource.href);
|
| 82 |
+
targetUrl.search = searchParams.toString();
|
| 83 |
+
res.redirect(targetUrl.toString());
|
| 84 |
+
}
|
| 85 |
+
async challengeForAuthorizationCode(_client, _authorizationCode) {
|
| 86 |
+
// In a proxy setup, we don't store the code challenge ourselves
|
| 87 |
+
// Instead, we proxy the token request and let the upstream server validate it
|
| 88 |
+
return '';
|
| 89 |
+
}
|
| 90 |
+
async exchangeAuthorizationCode(client, authorizationCode, codeVerifier, redirectUri, resource) {
|
| 91 |
+
const params = new URLSearchParams({
|
| 92 |
+
grant_type: 'authorization_code',
|
| 93 |
+
client_id: client.client_id,
|
| 94 |
+
code: authorizationCode
|
| 95 |
+
});
|
| 96 |
+
if (client.client_secret) {
|
| 97 |
+
params.append('client_secret', client.client_secret);
|
| 98 |
+
}
|
| 99 |
+
if (codeVerifier) {
|
| 100 |
+
params.append('code_verifier', codeVerifier);
|
| 101 |
+
}
|
| 102 |
+
if (redirectUri) {
|
| 103 |
+
params.append('redirect_uri', redirectUri);
|
| 104 |
+
}
|
| 105 |
+
if (resource) {
|
| 106 |
+
params.append('resource', resource.href);
|
| 107 |
+
}
|
| 108 |
+
const response = await (this._fetch ?? fetch)(this._endpoints.tokenUrl, {
|
| 109 |
+
method: 'POST',
|
| 110 |
+
headers: {
|
| 111 |
+
'Content-Type': 'application/x-www-form-urlencoded'
|
| 112 |
+
},
|
| 113 |
+
body: params.toString()
|
| 114 |
+
});
|
| 115 |
+
if (!response.ok) {
|
| 116 |
+
await response.body?.cancel();
|
| 117 |
+
throw new ServerError(`Token exchange failed: ${response.status}`);
|
| 118 |
+
}
|
| 119 |
+
const data = await response.json();
|
| 120 |
+
return OAuthTokensSchema.parse(data);
|
| 121 |
+
}
|
| 122 |
+
async exchangeRefreshToken(client, refreshToken, scopes, resource) {
|
| 123 |
+
const params = new URLSearchParams({
|
| 124 |
+
grant_type: 'refresh_token',
|
| 125 |
+
client_id: client.client_id,
|
| 126 |
+
refresh_token: refreshToken
|
| 127 |
+
});
|
| 128 |
+
if (client.client_secret) {
|
| 129 |
+
params.set('client_secret', client.client_secret);
|
| 130 |
+
}
|
| 131 |
+
if (scopes?.length) {
|
| 132 |
+
params.set('scope', scopes.join(' '));
|
| 133 |
+
}
|
| 134 |
+
if (resource) {
|
| 135 |
+
params.set('resource', resource.href);
|
| 136 |
+
}
|
| 137 |
+
const response = await (this._fetch ?? fetch)(this._endpoints.tokenUrl, {
|
| 138 |
+
method: 'POST',
|
| 139 |
+
headers: {
|
| 140 |
+
'Content-Type': 'application/x-www-form-urlencoded'
|
| 141 |
+
},
|
| 142 |
+
body: params.toString()
|
| 143 |
+
});
|
| 144 |
+
if (!response.ok) {
|
| 145 |
+
await response.body?.cancel();
|
| 146 |
+
throw new ServerError(`Token refresh failed: ${response.status}`);
|
| 147 |
+
}
|
| 148 |
+
const data = await response.json();
|
| 149 |
+
return OAuthTokensSchema.parse(data);
|
| 150 |
+
}
|
| 151 |
+
async verifyAccessToken(token) {
|
| 152 |
+
return this._verifyAccessToken(token);
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
//# sourceMappingURL=proxyProvider.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/providers/proxyProvider.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"proxyProvider.js","sourceRoot":"","sources":["../../../../../src/server/auth/providers/proxyProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAEH,gCAAgC,EAGhC,iBAAiB,EACpB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAgC3C;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAUjC,YAAY,OAAqB;QAJjC,4BAAuB,GAAG,IAAI,CAAC;QAK3B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACpD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,OAAO,CAAC,SAAS,EAAE,aAAa,EAAE,CAAC;YACnC,IAAI,CAAC,WAAW,GAAG,KAAK,EAAE,MAAkC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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express, { RequestHandler } from 'express';
|
| 2 |
+
import { ClientRegistrationHandlerOptions } from './handlers/register.js';
|
| 3 |
+
import { TokenHandlerOptions } from './handlers/token.js';
|
| 4 |
+
import { AuthorizationHandlerOptions } from './handlers/authorize.js';
|
| 5 |
+
import { RevocationHandlerOptions } from './handlers/revoke.js';
|
| 6 |
+
import { OAuthServerProvider } from './provider.js';
|
| 7 |
+
import { OAuthMetadata } from '../../shared/auth.js';
|
| 8 |
+
export type AuthRouterOptions = {
|
| 9 |
+
/**
|
| 10 |
+
* A provider implementing the actual authorization logic for this router.
|
| 11 |
+
*/
|
| 12 |
+
provider: OAuthServerProvider;
|
| 13 |
+
/**
|
| 14 |
+
* The authorization server's issuer identifier, which is a URL that uses the "https" scheme and has no query or fragment components.
|
| 15 |
+
*/
|
| 16 |
+
issuerUrl: URL;
|
| 17 |
+
/**
|
| 18 |
+
* The base URL of the authorization server to use for the metadata endpoints.
|
| 19 |
+
*
|
| 20 |
+
* If not provided, the issuer URL will be used as the base URL.
|
| 21 |
+
*/
|
| 22 |
+
baseUrl?: URL;
|
| 23 |
+
/**
|
| 24 |
+
* An optional URL of a page containing human-readable information that developers might want or need to know when using the authorization server.
|
| 25 |
+
*/
|
| 26 |
+
serviceDocumentationUrl?: URL;
|
| 27 |
+
/**
|
| 28 |
+
* An optional list of scopes supported by this authorization server
|
| 29 |
+
*/
|
| 30 |
+
scopesSupported?: string[];
|
| 31 |
+
/**
|
| 32 |
+
* The resource name to be displayed in protected resource metadata
|
| 33 |
+
*/
|
| 34 |
+
resourceName?: string;
|
| 35 |
+
/**
|
| 36 |
+
* The URL of the protected resource (RS) whose metadata we advertise.
|
| 37 |
+
* If not provided, falls back to `baseUrl` and then to `issuerUrl` (AS=RS).
|
| 38 |
+
*/
|
| 39 |
+
resourceServerUrl?: URL;
|
| 40 |
+
authorizationOptions?: Omit<AuthorizationHandlerOptions, 'provider'>;
|
| 41 |
+
clientRegistrationOptions?: Omit<ClientRegistrationHandlerOptions, 'clientsStore'>;
|
| 42 |
+
revocationOptions?: Omit<RevocationHandlerOptions, 'provider'>;
|
| 43 |
+
tokenOptions?: Omit<TokenHandlerOptions, 'provider'>;
|
| 44 |
+
};
|
| 45 |
+
export declare const createOAuthMetadata: (options: {
|
| 46 |
+
provider: OAuthServerProvider;
|
| 47 |
+
issuerUrl: URL;
|
| 48 |
+
baseUrl?: URL;
|
| 49 |
+
serviceDocumentationUrl?: URL;
|
| 50 |
+
scopesSupported?: string[];
|
| 51 |
+
}) => OAuthMetadata;
|
| 52 |
+
/**
|
| 53 |
+
* Installs standard MCP authorization server endpoints, including dynamic client registration and token revocation (if supported).
|
| 54 |
+
* Also advertises standard authorization server metadata, for easier discovery of supported configurations by clients.
|
| 55 |
+
* Note: if your MCP server is only a resource server and not an authorization server, use mcpAuthMetadataRouter instead.
|
| 56 |
+
*
|
| 57 |
+
* By default, rate limiting is applied to all endpoints to prevent abuse.
|
| 58 |
+
*
|
| 59 |
+
* This router MUST be installed at the application root, like so:
|
| 60 |
+
*
|
| 61 |
+
* const app = express();
|
| 62 |
+
* app.use(mcpAuthRouter(...));
|
| 63 |
+
*/
|
| 64 |
+
export declare function mcpAuthRouter(options: AuthRouterOptions): RequestHandler;
|
| 65 |
+
export type AuthMetadataOptions = {
|
| 66 |
+
/**
|
| 67 |
+
* OAuth Metadata as would be returned from the authorization server
|
| 68 |
+
* this MCP server relies on
|
| 69 |
+
*/
|
| 70 |
+
oauthMetadata: OAuthMetadata;
|
| 71 |
+
/**
|
| 72 |
+
* The url of the MCP server, for use in protected resource metadata
|
| 73 |
+
*/
|
| 74 |
+
resourceServerUrl: URL;
|
| 75 |
+
/**
|
| 76 |
+
* The url for documentation for the MCP server
|
| 77 |
+
*/
|
| 78 |
+
serviceDocumentationUrl?: URL;
|
| 79 |
+
/**
|
| 80 |
+
* An optional list of scopes supported by this MCP server
|
| 81 |
+
*/
|
| 82 |
+
scopesSupported?: string[];
|
| 83 |
+
/**
|
| 84 |
+
* An optional resource name to display in resource metadata
|
| 85 |
+
*/
|
| 86 |
+
resourceName?: string;
|
| 87 |
+
};
|
| 88 |
+
export declare function mcpAuthMetadataRouter(options: AuthMetadataOptions): express.Router;
|
| 89 |
+
/**
|
| 90 |
+
* Helper function to construct the OAuth 2.0 Protected Resource Metadata URL
|
| 91 |
+
* from a given server URL. This replaces the path with the standard metadata endpoint.
|
| 92 |
+
*
|
| 93 |
+
* @param serverUrl - The base URL of the protected resource server
|
| 94 |
+
* @returns The URL for the OAuth protected resource metadata endpoint
|
| 95 |
+
*
|
| 96 |
+
* @example
|
| 97 |
+
* getOAuthProtectedResourceMetadataUrl(new URL('https://api.example.com/mcp'))
|
| 98 |
+
* // Returns: 'https://api.example.com/.well-known/oauth-protected-resource/mcp'
|
| 99 |
+
*/
|
| 100 |
+
export declare function getOAuthProtectedResourceMetadataUrl(serverUrl: URL): string;
|
| 101 |
+
//# sourceMappingURL=router.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/router.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/router.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAA6B,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAgB,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAwB,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAqB,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAEnF,OAAO,EAAE,mBAAm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|
|
|
|
|
|
|
| 1 |
+
import express from 'express';
|
| 2 |
+
import { clientRegistrationHandler } from './handlers/register.js';
|
| 3 |
+
import { tokenHandler } from './handlers/token.js';
|
| 4 |
+
import { authorizationHandler } from './handlers/authorize.js';
|
| 5 |
+
import { revocationHandler } from './handlers/revoke.js';
|
| 6 |
+
import { metadataHandler } from './handlers/metadata.js';
|
| 7 |
+
// Check for dev mode flag that allows HTTP issuer URLs (for development/testing only)
|
| 8 |
+
const allowInsecureIssuerUrl = process.env.MCP_DANGEROUSLY_ALLOW_INSECURE_ISSUER_URL === 'true' || process.env.MCP_DANGEROUSLY_ALLOW_INSECURE_ISSUER_URL === '1';
|
| 9 |
+
if (allowInsecureIssuerUrl) {
|
| 10 |
+
// eslint-disable-next-line no-console
|
| 11 |
+
console.warn('MCP_DANGEROUSLY_ALLOW_INSECURE_ISSUER_URL is enabled - HTTP issuer URLs are allowed. Do not use in production.');
|
| 12 |
+
}
|
| 13 |
+
const checkIssuerUrl = (issuer) => {
|
| 14 |
+
// Technically RFC 8414 does not permit a localhost HTTPS exemption, but this will be necessary for ease of testing
|
| 15 |
+
if (issuer.protocol !== 'https:' && issuer.hostname !== 'localhost' && issuer.hostname !== '127.0.0.1' && !allowInsecureIssuerUrl) {
|
| 16 |
+
throw new Error('Issuer URL must be HTTPS');
|
| 17 |
+
}
|
| 18 |
+
if (issuer.hash) {
|
| 19 |
+
throw new Error(`Issuer URL must not have a fragment: ${issuer}`);
|
| 20 |
+
}
|
| 21 |
+
if (issuer.search) {
|
| 22 |
+
throw new Error(`Issuer URL must not have a query string: ${issuer}`);
|
| 23 |
+
}
|
| 24 |
+
};
|
| 25 |
+
export const createOAuthMetadata = (options) => {
|
| 26 |
+
const issuer = options.issuerUrl;
|
| 27 |
+
const baseUrl = options.baseUrl;
|
| 28 |
+
checkIssuerUrl(issuer);
|
| 29 |
+
const authorization_endpoint = '/authorize';
|
| 30 |
+
const token_endpoint = '/token';
|
| 31 |
+
const registration_endpoint = options.provider.clientsStore.registerClient ? '/register' : undefined;
|
| 32 |
+
const revocation_endpoint = options.provider.revokeToken ? '/revoke' : undefined;
|
| 33 |
+
const metadata = {
|
| 34 |
+
issuer: issuer.href,
|
| 35 |
+
service_documentation: options.serviceDocumentationUrl?.href,
|
| 36 |
+
authorization_endpoint: new URL(authorization_endpoint, baseUrl || issuer).href,
|
| 37 |
+
response_types_supported: ['code'],
|
| 38 |
+
code_challenge_methods_supported: ['S256'],
|
| 39 |
+
token_endpoint: new URL(token_endpoint, baseUrl || issuer).href,
|
| 40 |
+
token_endpoint_auth_methods_supported: ['client_secret_post', 'none'],
|
| 41 |
+
grant_types_supported: ['authorization_code', 'refresh_token'],
|
| 42 |
+
scopes_supported: options.scopesSupported,
|
| 43 |
+
revocation_endpoint: revocation_endpoint ? new URL(revocation_endpoint, baseUrl || issuer).href : undefined,
|
| 44 |
+
revocation_endpoint_auth_methods_supported: revocation_endpoint ? ['client_secret_post'] : undefined,
|
| 45 |
+
registration_endpoint: registration_endpoint ? new URL(registration_endpoint, baseUrl || issuer).href : undefined
|
| 46 |
+
};
|
| 47 |
+
return metadata;
|
| 48 |
+
};
|
| 49 |
+
/**
|
| 50 |
+
* Installs standard MCP authorization server endpoints, including dynamic client registration and token revocation (if supported).
|
| 51 |
+
* Also advertises standard authorization server metadata, for easier discovery of supported configurations by clients.
|
| 52 |
+
* Note: if your MCP server is only a resource server and not an authorization server, use mcpAuthMetadataRouter instead.
|
| 53 |
+
*
|
| 54 |
+
* By default, rate limiting is applied to all endpoints to prevent abuse.
|
| 55 |
+
*
|
| 56 |
+
* This router MUST be installed at the application root, like so:
|
| 57 |
+
*
|
| 58 |
+
* const app = express();
|
| 59 |
+
* app.use(mcpAuthRouter(...));
|
| 60 |
+
*/
|
| 61 |
+
export function mcpAuthRouter(options) {
|
| 62 |
+
const oauthMetadata = createOAuthMetadata(options);
|
| 63 |
+
const router = express.Router();
|
| 64 |
+
router.use(new URL(oauthMetadata.authorization_endpoint).pathname, authorizationHandler({ provider: options.provider, ...options.authorizationOptions }));
|
| 65 |
+
router.use(new URL(oauthMetadata.token_endpoint).pathname, tokenHandler({ provider: options.provider, ...options.tokenOptions }));
|
| 66 |
+
router.use(mcpAuthMetadataRouter({
|
| 67 |
+
oauthMetadata,
|
| 68 |
+
// Prefer explicit RS; otherwise fall back to AS baseUrl, then to issuer (back-compat)
|
| 69 |
+
resourceServerUrl: options.resourceServerUrl ?? options.baseUrl ?? new URL(oauthMetadata.issuer),
|
| 70 |
+
serviceDocumentationUrl: options.serviceDocumentationUrl,
|
| 71 |
+
scopesSupported: options.scopesSupported,
|
| 72 |
+
resourceName: options.resourceName
|
| 73 |
+
}));
|
| 74 |
+
if (oauthMetadata.registration_endpoint) {
|
| 75 |
+
router.use(new URL(oauthMetadata.registration_endpoint).pathname, clientRegistrationHandler({
|
| 76 |
+
clientsStore: options.provider.clientsStore,
|
| 77 |
+
...options.clientRegistrationOptions
|
| 78 |
+
}));
|
| 79 |
+
}
|
| 80 |
+
if (oauthMetadata.revocation_endpoint) {
|
| 81 |
+
router.use(new URL(oauthMetadata.revocation_endpoint).pathname, revocationHandler({ provider: options.provider, ...options.revocationOptions }));
|
| 82 |
+
}
|
| 83 |
+
return router;
|
| 84 |
+
}
|
| 85 |
+
export function mcpAuthMetadataRouter(options) {
|
| 86 |
+
checkIssuerUrl(new URL(options.oauthMetadata.issuer));
|
| 87 |
+
const router = express.Router();
|
| 88 |
+
const protectedResourceMetadata = {
|
| 89 |
+
resource: options.resourceServerUrl.href,
|
| 90 |
+
authorization_servers: [options.oauthMetadata.issuer],
|
| 91 |
+
scopes_supported: options.scopesSupported,
|
| 92 |
+
resource_name: options.resourceName,
|
| 93 |
+
resource_documentation: options.serviceDocumentationUrl?.href
|
| 94 |
+
};
|
| 95 |
+
// Serve PRM at the path-specific URL per RFC 9728
|
| 96 |
+
const rsPath = new URL(options.resourceServerUrl.href).pathname;
|
| 97 |
+
router.use(`/.well-known/oauth-protected-resource${rsPath === '/' ? '' : rsPath}`, metadataHandler(protectedResourceMetadata));
|
| 98 |
+
// Always add this for OAuth Authorization Server metadata per RFC 8414
|
| 99 |
+
router.use('/.well-known/oauth-authorization-server', metadataHandler(options.oauthMetadata));
|
| 100 |
+
return router;
|
| 101 |
+
}
|
| 102 |
+
/**
|
| 103 |
+
* Helper function to construct the OAuth 2.0 Protected Resource Metadata URL
|
| 104 |
+
* from a given server URL. This replaces the path with the standard metadata endpoint.
|
| 105 |
+
*
|
| 106 |
+
* @param serverUrl - The base URL of the protected resource server
|
| 107 |
+
* @returns The URL for the OAuth protected resource metadata endpoint
|
| 108 |
+
*
|
| 109 |
+
* @example
|
| 110 |
+
* getOAuthProtectedResourceMetadataUrl(new URL('https://api.example.com/mcp'))
|
| 111 |
+
* // Returns: 'https://api.example.com/.well-known/oauth-protected-resource/mcp'
|
| 112 |
+
*/
|
| 113 |
+
export function getOAuthProtectedResourceMetadataUrl(serverUrl) {
|
| 114 |
+
const u = new URL(serverUrl.href);
|
| 115 |
+
const rsPath = u.pathname && u.pathname !== '/' ? u.pathname : '';
|
| 116 |
+
return new URL(`/.well-known/oauth-protected-resource${rsPath}`, u).href;
|
| 117 |
+
}
|
| 118 |
+
//# sourceMappingURL=router.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/router.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../../src/server/auth/router.ts"],"names":[],"mappings":"AAAA,OAAO,OAA2B,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAoC,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAE,YAAY,EAAuB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAA+B,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAA4B,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI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AAC;AAC7E,CAAC"}
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/types.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Information about a validated access token, provided to request handlers.
|
| 3 |
+
*/
|
| 4 |
+
export interface AuthInfo {
|
| 5 |
+
/**
|
| 6 |
+
* The access token.
|
| 7 |
+
*/
|
| 8 |
+
token: string;
|
| 9 |
+
/**
|
| 10 |
+
* The client ID associated with this token.
|
| 11 |
+
*/
|
| 12 |
+
clientId: string;
|
| 13 |
+
/**
|
| 14 |
+
* Scopes associated with this token.
|
| 15 |
+
*/
|
| 16 |
+
scopes: string[];
|
| 17 |
+
/**
|
| 18 |
+
* When the token expires (in seconds since epoch).
|
| 19 |
+
*/
|
| 20 |
+
expiresAt?: number;
|
| 21 |
+
/**
|
| 22 |
+
* The RFC 8707 resource server identifier for which this token is valid.
|
| 23 |
+
* If set, this MUST match the MCP server's resource identifier (minus hash fragment).
|
| 24 |
+
*/
|
| 25 |
+
resource?: URL;
|
| 26 |
+
/**
|
| 27 |
+
* Additional data associated with the token.
|
| 28 |
+
* This field should be used for any additional data that needs to be attached to the auth info.
|
| 29 |
+
*/
|
| 30 |
+
extra?: Record<string, unknown>;
|
| 31 |
+
}
|
| 32 |
+
//# sourceMappingURL=types.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/types.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/server/auth/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC"}
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/types.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export {};
|
| 2 |
+
//# sourceMappingURL=types.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/server/auth/types.ts"],"names":[],"mappings":""}
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { AnySchema, SchemaInput } from './zod-compat.js';
|
| 2 |
+
export declare const COMPLETABLE_SYMBOL: unique symbol;
|
| 3 |
+
export type CompleteCallback<T extends AnySchema = AnySchema> = (value: SchemaInput<T>, context?: {
|
| 4 |
+
arguments?: Record<string, string>;
|
| 5 |
+
}) => SchemaInput<T>[] | Promise<SchemaInput<T>[]>;
|
| 6 |
+
export type CompletableMeta<T extends AnySchema = AnySchema> = {
|
| 7 |
+
complete: CompleteCallback<T>;
|
| 8 |
+
};
|
| 9 |
+
export type CompletableSchema<T extends AnySchema> = T & {
|
| 10 |
+
[COMPLETABLE_SYMBOL]: CompletableMeta<T>;
|
| 11 |
+
};
|
| 12 |
+
/**
|
| 13 |
+
* Wraps a Zod type to provide autocompletion capabilities. Useful for, e.g., prompt arguments in MCP.
|
| 14 |
+
* Works with both Zod v3 and v4 schemas.
|
| 15 |
+
*/
|
| 16 |
+
export declare function completable<T extends AnySchema>(schema: T, complete: CompleteCallback<T>): CompletableSchema<T>;
|
| 17 |
+
/**
|
| 18 |
+
* Checks if a schema is completable (has completion metadata).
|
| 19 |
+
*/
|
| 20 |
+
export declare function isCompletable(schema: unknown): schema is CompletableSchema<AnySchema>;
|
| 21 |
+
/**
|
| 22 |
+
* Gets the completer callback from a completable schema, if it exists.
|
| 23 |
+
*/
|
| 24 |
+
export declare function getCompleter<T extends AnySchema>(schema: T): CompleteCallback<T> | undefined;
|
| 25 |
+
/**
|
| 26 |
+
* Unwraps a completable schema to get the underlying schema.
|
| 27 |
+
* For backward compatibility with code that called `.unwrap()`.
|
| 28 |
+
*/
|
| 29 |
+
export declare function unwrapCompletable<T extends AnySchema>(schema: CompletableSchema<T>): T;
|
| 30 |
+
export declare enum McpZodTypeKind {
|
| 31 |
+
Completable = "McpCompletable"
|
| 32 |
+
}
|
| 33 |
+
export interface CompletableDef<T extends AnySchema = AnySchema> {
|
| 34 |
+
type: T;
|
| 35 |
+
complete: CompleteCallback<T>;
|
| 36 |
+
typeName: McpZodTypeKind.Completable;
|
| 37 |
+
}
|
| 38 |
+
//# sourceMappingURL=completable.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"completable.d.ts","sourceRoot":"","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CAAC,GAAG,CAAC,CAEtF;AAID,oBAAY,cAAc;IACtB,WAAW,mBAAmB;CACjC;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC3D,IAAI,EAAE,CAAC,CAAC;IACR,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC9B,QAAQ,EAAE,cAAc,CAAC,WAAW,CAAC;CACxC"}
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export const COMPLETABLE_SYMBOL = Symbol.for('mcp.completable');
|
| 2 |
+
/**
|
| 3 |
+
* Wraps a Zod type to provide autocompletion capabilities. Useful for, e.g., prompt arguments in MCP.
|
| 4 |
+
* Works with both Zod v3 and v4 schemas.
|
| 5 |
+
*/
|
| 6 |
+
export function completable(schema, complete) {
|
| 7 |
+
Object.defineProperty(schema, COMPLETABLE_SYMBOL, {
|
| 8 |
+
value: { complete },
|
| 9 |
+
enumerable: false,
|
| 10 |
+
writable: false,
|
| 11 |
+
configurable: false
|
| 12 |
+
});
|
| 13 |
+
return schema;
|
| 14 |
+
}
|
| 15 |
+
/**
|
| 16 |
+
* Checks if a schema is completable (has completion metadata).
|
| 17 |
+
*/
|
| 18 |
+
export function isCompletable(schema) {
|
| 19 |
+
return !!schema && typeof schema === 'object' && COMPLETABLE_SYMBOL in schema;
|
| 20 |
+
}
|
| 21 |
+
/**
|
| 22 |
+
* Gets the completer callback from a completable schema, if it exists.
|
| 23 |
+
*/
|
| 24 |
+
export function getCompleter(schema) {
|
| 25 |
+
const meta = schema[COMPLETABLE_SYMBOL];
|
| 26 |
+
return meta?.complete;
|
| 27 |
+
}
|
| 28 |
+
/**
|
| 29 |
+
* Unwraps a completable schema to get the underlying schema.
|
| 30 |
+
* For backward compatibility with code that called `.unwrap()`.
|
| 31 |
+
*/
|
| 32 |
+
export function unwrapCompletable(schema) {
|
| 33 |
+
return schema;
|
| 34 |
+
}
|
| 35 |
+
// Legacy exports for backward compatibility
|
| 36 |
+
// These types are deprecated but kept for existing code
|
| 37 |
+
export var McpZodTypeKind;
|
| 38 |
+
(function (McpZodTypeKind) {
|
| 39 |
+
McpZodTypeKind["Completable"] = "McpCompletable";
|
| 40 |
+
})(McpZodTypeKind || (McpZodTypeKind = {}));
|
| 41 |
+
//# sourceMappingURL=completable.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"completable.js","sourceRoot":"","sources":["../../../src/server/completable.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kBAAkB,GAAkB,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAiB/E;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAsB,MAAS,EAAE,QAA6B;IACrF,MAAM,CAAC,cAAc,CAAC,MAAgB,EAAE,kBAAkB,EAAE;QACxD,KAAK,EAAE,EAAE,QAAQ,EAAwB;QACzC,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,KAAK;KACtB,CAAC,CAAC;IACH,OAAO,MAA8B,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAe;IACzC,OAAO,CAAC,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,kBAAkB,IAAK,MAAiB,CAAC;AAC9F,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAsB,MAAS;IACvD,MAAM,IAAI,GAAI,MAAmE,CAAC,kBAAkB,CAAC,CAAC;IACtG,OAAO,IAAI,EAAE,QAA2C,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAsB,MAA4B;IAC/E,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,4CAA4C;AAC5C,wDAAwD;AACxD,MAAM,CAAN,IAAY,cAEX;AAFD,WAAY,cAAc;IACtB,gDAA8B,CAAA;AAClC,CAAC,EAFW,cAAc,KAAd,cAAc,QAEzB"}
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Express } from 'express';
|
| 2 |
+
/**
|
| 3 |
+
* Options for creating an MCP Express application.
|
| 4 |
+
*/
|
| 5 |
+
export interface CreateMcpExpressAppOptions {
|
| 6 |
+
/**
|
| 7 |
+
* The hostname to bind to. Defaults to '127.0.0.1'.
|
| 8 |
+
* When set to '127.0.0.1', 'localhost', or '::1', DNS rebinding protection is automatically enabled.
|
| 9 |
+
*/
|
| 10 |
+
host?: string;
|
| 11 |
+
/**
|
| 12 |
+
* List of allowed hostnames for DNS rebinding protection.
|
| 13 |
+
* If provided, host header validation will be applied using this list.
|
| 14 |
+
* For IPv6, provide addresses with brackets (e.g., '[::1]').
|
| 15 |
+
*
|
| 16 |
+
* This is useful when binding to '0.0.0.0' or '::' but still wanting
|
| 17 |
+
* to restrict which hostnames are allowed.
|
| 18 |
+
*/
|
| 19 |
+
allowedHosts?: string[];
|
| 20 |
+
}
|
| 21 |
+
/**
|
| 22 |
+
* Creates an Express application pre-configured for MCP servers.
|
| 23 |
+
*
|
| 24 |
+
* When the host is '127.0.0.1', 'localhost', or '::1' (the default is '127.0.0.1'),
|
| 25 |
+
* DNS rebinding protection middleware is automatically applied to protect against
|
| 26 |
+
* DNS rebinding attacks on localhost servers.
|
| 27 |
+
*
|
| 28 |
+
* @param options - Configuration options
|
| 29 |
+
* @returns A configured Express application
|
| 30 |
+
*
|
| 31 |
+
* @example
|
| 32 |
+
* ```typescript
|
| 33 |
+
* // Basic usage - defaults to 127.0.0.1 with DNS rebinding protection
|
| 34 |
+
* const app = createMcpExpressApp();
|
| 35 |
+
*
|
| 36 |
+
* // Custom host - DNS rebinding protection only applied for localhost hosts
|
| 37 |
+
* const app = createMcpExpressApp({ host: '0.0.0.0' }); // No automatic DNS rebinding protection
|
| 38 |
+
* const app = createMcpExpressApp({ host: 'localhost' }); // DNS rebinding protection enabled
|
| 39 |
+
*
|
| 40 |
+
* // Custom allowed hosts for non-localhost binding
|
| 41 |
+
* const app = createMcpExpressApp({ host: '0.0.0.0', allowedHosts: ['myapp.local', 'localhost'] });
|
| 42 |
+
* ```
|
| 43 |
+
*/
|
| 44 |
+
export declare function createMcpExpressApp(options?: CreateMcpExpressAppOptions): Express;
|
| 45 |
+
//# sourceMappingURL=express.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../../src/server/express.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG3C;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACvC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA0BrF"}
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import express from 'express';
|
| 2 |
+
import { hostHeaderValidation, localhostHostValidation } from './middleware/hostHeaderValidation.js';
|
| 3 |
+
/**
|
| 4 |
+
* Creates an Express application pre-configured for MCP servers.
|
| 5 |
+
*
|
| 6 |
+
* When the host is '127.0.0.1', 'localhost', or '::1' (the default is '127.0.0.1'),
|
| 7 |
+
* DNS rebinding protection middleware is automatically applied to protect against
|
| 8 |
+
* DNS rebinding attacks on localhost servers.
|
| 9 |
+
*
|
| 10 |
+
* @param options - Configuration options
|
| 11 |
+
* @returns A configured Express application
|
| 12 |
+
*
|
| 13 |
+
* @example
|
| 14 |
+
* ```typescript
|
| 15 |
+
* // Basic usage - defaults to 127.0.0.1 with DNS rebinding protection
|
| 16 |
+
* const app = createMcpExpressApp();
|
| 17 |
+
*
|
| 18 |
+
* // Custom host - DNS rebinding protection only applied for localhost hosts
|
| 19 |
+
* const app = createMcpExpressApp({ host: '0.0.0.0' }); // No automatic DNS rebinding protection
|
| 20 |
+
* const app = createMcpExpressApp({ host: 'localhost' }); // DNS rebinding protection enabled
|
| 21 |
+
*
|
| 22 |
+
* // Custom allowed hosts for non-localhost binding
|
| 23 |
+
* const app = createMcpExpressApp({ host: '0.0.0.0', allowedHosts: ['myapp.local', 'localhost'] });
|
| 24 |
+
* ```
|
| 25 |
+
*/
|
| 26 |
+
export function createMcpExpressApp(options = {}) {
|
| 27 |
+
const { host = '127.0.0.1', allowedHosts } = options;
|
| 28 |
+
const app = express();
|
| 29 |
+
app.use(express.json());
|
| 30 |
+
// If allowedHosts is explicitly provided, use that for validation
|
| 31 |
+
if (allowedHosts) {
|
| 32 |
+
app.use(hostHeaderValidation(allowedHosts));
|
| 33 |
+
}
|
| 34 |
+
else {
|
| 35 |
+
// Apply DNS rebinding protection automatically for localhost hosts
|
| 36 |
+
const localhostHosts = ['127.0.0.1', 'localhost', '::1'];
|
| 37 |
+
if (localhostHosts.includes(host)) {
|
| 38 |
+
app.use(localhostHostValidation());
|
| 39 |
+
}
|
| 40 |
+
else if (host === '0.0.0.0' || host === '::') {
|
| 41 |
+
// Warn when binding to all interfaces without DNS rebinding protection
|
| 42 |
+
// eslint-disable-next-line no-console
|
| 43 |
+
console.warn(`Warning: Server is binding to ${host} without DNS rebinding protection. ` +
|
| 44 |
+
'Consider using the allowedHosts option to restrict allowed hosts, ' +
|
| 45 |
+
'or use authentication to protect your server.');
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
return app;
|
| 49 |
+
}
|
| 50 |
+
//# sourceMappingURL=express.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../../src/server/express.ts"],"names":[],"mappings":"AAAA,OAAO,OAAoB,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AA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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Protocol, type NotificationOptions, type ProtocolOptions, type RequestOptions } from '../shared/protocol.js';
|
| 2 |
+
import { type ClientCapabilities, type CreateMessageRequest, type CreateMessageResult, type CreateMessageResultWithTools, type CreateMessageRequestParamsBase, type CreateMessageRequestParamsWithTools, type ElicitRequestFormParams, type ElicitRequestURLParams, type ElicitResult, type Implementation, type ListRootsRequest, type LoggingMessageNotification, type ResourceUpdatedNotification, type ServerCapabilities, type ServerNotification, type ServerRequest, type ServerResult, type Request, type Notification, type Result } from '../types.js';
|
| 3 |
+
import type { jsonSchemaValidator } from '../validation/types.js';
|
| 4 |
+
import { AnyObjectSchema, SchemaOutput } from './zod-compat.js';
|
| 5 |
+
import { RequestHandlerExtra } from '../shared/protocol.js';
|
| 6 |
+
import { ExperimentalServerTasks } from '../experimental/tasks/server.js';
|
| 7 |
+
export type ServerOptions = ProtocolOptions & {
|
| 8 |
+
/**
|
| 9 |
+
* Capabilities to advertise as being supported by this server.
|
| 10 |
+
*/
|
| 11 |
+
capabilities?: ServerCapabilities;
|
| 12 |
+
/**
|
| 13 |
+
* Optional instructions describing how to use the server and its features.
|
| 14 |
+
*/
|
| 15 |
+
instructions?: string;
|
| 16 |
+
/**
|
| 17 |
+
* JSON Schema validator for elicitation response validation.
|
| 18 |
+
*
|
| 19 |
+
* The validator is used to validate user input returned from elicitation
|
| 20 |
+
* requests against the requested schema.
|
| 21 |
+
*
|
| 22 |
+
* @default AjvJsonSchemaValidator
|
| 23 |
+
*
|
| 24 |
+
* @example
|
| 25 |
+
* ```typescript
|
| 26 |
+
* // ajv (default)
|
| 27 |
+
* const server = new Server(
|
| 28 |
+
* { name: 'my-server', version: '1.0.0' },
|
| 29 |
+
* {
|
| 30 |
+
* capabilities: {}
|
| 31 |
+
* jsonSchemaValidator: new AjvJsonSchemaValidator()
|
| 32 |
+
* }
|
| 33 |
+
* );
|
| 34 |
+
*
|
| 35 |
+
* // @cfworker/json-schema
|
| 36 |
+
* const server = new Server(
|
| 37 |
+
* { name: 'my-server', version: '1.0.0' },
|
| 38 |
+
* {
|
| 39 |
+
* capabilities: {},
|
| 40 |
+
* jsonSchemaValidator: new CfWorkerJsonSchemaValidator()
|
| 41 |
+
* }
|
| 42 |
+
* );
|
| 43 |
+
* ```
|
| 44 |
+
*/
|
| 45 |
+
jsonSchemaValidator?: jsonSchemaValidator;
|
| 46 |
+
};
|
| 47 |
+
/**
|
| 48 |
+
* An MCP server on top of a pluggable transport.
|
| 49 |
+
*
|
| 50 |
+
* This server will automatically respond to the initialization flow as initiated from the client.
|
| 51 |
+
*
|
| 52 |
+
* To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters:
|
| 53 |
+
*
|
| 54 |
+
* ```typescript
|
| 55 |
+
* // Custom schemas
|
| 56 |
+
* const CustomRequestSchema = RequestSchema.extend({...})
|
| 57 |
+
* const CustomNotificationSchema = NotificationSchema.extend({...})
|
| 58 |
+
* const CustomResultSchema = ResultSchema.extend({...})
|
| 59 |
+
*
|
| 60 |
+
* // Type aliases
|
| 61 |
+
* type CustomRequest = z.infer<typeof CustomRequestSchema>
|
| 62 |
+
* type CustomNotification = z.infer<typeof CustomNotificationSchema>
|
| 63 |
+
* type CustomResult = z.infer<typeof CustomResultSchema>
|
| 64 |
+
*
|
| 65 |
+
* // Create typed server
|
| 66 |
+
* const server = new Server<CustomRequest, CustomNotification, CustomResult>({
|
| 67 |
+
* name: "CustomServer",
|
| 68 |
+
* version: "1.0.0"
|
| 69 |
+
* })
|
| 70 |
+
* ```
|
| 71 |
+
* @deprecated Use `McpServer` instead for the high-level API. Only use `Server` for advanced use cases.
|
| 72 |
+
*/
|
| 73 |
+
export declare class Server<RequestT extends Request = Request, NotificationT extends Notification = Notification, ResultT extends Result = Result> extends Protocol<ServerRequest | RequestT, ServerNotification | NotificationT, ServerResult | ResultT> {
|
| 74 |
+
private _serverInfo;
|
| 75 |
+
private _clientCapabilities?;
|
| 76 |
+
private _clientVersion?;
|
| 77 |
+
private _capabilities;
|
| 78 |
+
private _instructions?;
|
| 79 |
+
private _jsonSchemaValidator;
|
| 80 |
+
private _experimental?;
|
| 81 |
+
/**
|
| 82 |
+
* Callback for when initialization has fully completed (i.e., the client has sent an `initialized` notification).
|
| 83 |
+
*/
|
| 84 |
+
oninitialized?: () => void;
|
| 85 |
+
/**
|
| 86 |
+
* Initializes this server with the given name and version information.
|
| 87 |
+
*/
|
| 88 |
+
constructor(_serverInfo: Implementation, options?: ServerOptions);
|
| 89 |
+
/**
|
| 90 |
+
* Access experimental features.
|
| 91 |
+
*
|
| 92 |
+
* WARNING: These APIs are experimental and may change without notice.
|
| 93 |
+
*
|
| 94 |
+
* @experimental
|
| 95 |
+
*/
|
| 96 |
+
get experimental(): {
|
| 97 |
+
tasks: ExperimentalServerTasks<RequestT, NotificationT, ResultT>;
|
| 98 |
+
};
|
| 99 |
+
private _loggingLevels;
|
| 100 |
+
private readonly LOG_LEVEL_SEVERITY;
|
| 101 |
+
private isMessageIgnored;
|
| 102 |
+
/**
|
| 103 |
+
* Registers new capabilities. This can only be called before connecting to a transport.
|
| 104 |
+
*
|
| 105 |
+
* The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
|
| 106 |
+
*/
|
| 107 |
+
registerCapabilities(capabilities: ServerCapabilities): void;
|
| 108 |
+
/**
|
| 109 |
+
* Override request handler registration to enforce server-side validation for tools/call.
|
| 110 |
+
*/
|
| 111 |
+
setRequestHandler<T extends AnyObjectSchema>(requestSchema: T, handler: (request: SchemaOutput<T>, extra: RequestHandlerExtra<ServerRequest | RequestT, ServerNotification | NotificationT>) => ServerResult | ResultT | Promise<ServerResult | ResultT>): void;
|
| 112 |
+
protected assertCapabilityForMethod(method: RequestT['method']): void;
|
| 113 |
+
protected assertNotificationCapability(method: (ServerNotification | NotificationT)['method']): void;
|
| 114 |
+
protected assertRequestHandlerCapability(method: string): void;
|
| 115 |
+
protected assertTaskCapability(method: string): void;
|
| 116 |
+
protected assertTaskHandlerCapability(method: string): void;
|
| 117 |
+
private _oninitialize;
|
| 118 |
+
/**
|
| 119 |
+
* After initialization has completed, this will be populated with the client's reported capabilities.
|
| 120 |
+
*/
|
| 121 |
+
getClientCapabilities(): ClientCapabilities | undefined;
|
| 122 |
+
/**
|
| 123 |
+
* After initialization has completed, this will be populated with information about the client's name and version.
|
| 124 |
+
*/
|
| 125 |
+
getClientVersion(): Implementation | undefined;
|
| 126 |
+
private getCapabilities;
|
| 127 |
+
ping(): Promise<{
|
| 128 |
+
_meta?: {
|
| 129 |
+
[x: string]: unknown;
|
| 130 |
+
progressToken?: string | number | undefined;
|
| 131 |
+
"io.modelcontextprotocol/related-task"?: {
|
| 132 |
+
taskId: string;
|
| 133 |
+
} | undefined;
|
| 134 |
+
} | undefined;
|
| 135 |
+
}>;
|
| 136 |
+
/**
|
| 137 |
+
* Request LLM sampling from the client (without tools).
|
| 138 |
+
* Returns single content block for backwards compatibility.
|
| 139 |
+
*/
|
| 140 |
+
createMessage(params: CreateMessageRequestParamsBase, options?: RequestOptions): Promise<CreateMessageResult>;
|
| 141 |
+
/**
|
| 142 |
+
* Request LLM sampling from the client with tool support.
|
| 143 |
+
* Returns content that may be a single block or array (for parallel tool calls).
|
| 144 |
+
*/
|
| 145 |
+
createMessage(params: CreateMessageRequestParamsWithTools, options?: RequestOptions): Promise<CreateMessageResultWithTools>;
|
| 146 |
+
/**
|
| 147 |
+
* Request LLM sampling from the client.
|
| 148 |
+
* When tools may or may not be present, returns the union type.
|
| 149 |
+
*/
|
| 150 |
+
createMessage(params: CreateMessageRequest['params'], options?: RequestOptions): Promise<CreateMessageResult | CreateMessageResultWithTools>;
|
| 151 |
+
/**
|
| 152 |
+
* Creates an elicitation request for the given parameters.
|
| 153 |
+
* For backwards compatibility, `mode` may be omitted for form requests and will default to `'form'`.
|
| 154 |
+
* @param params The parameters for the elicitation request.
|
| 155 |
+
* @param options Optional request options.
|
| 156 |
+
* @returns The result of the elicitation request.
|
| 157 |
+
*/
|
| 158 |
+
elicitInput(params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions): Promise<ElicitResult>;
|
| 159 |
+
/**
|
| 160 |
+
* Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete`
|
| 161 |
+
* notification for the specified elicitation ID.
|
| 162 |
+
*
|
| 163 |
+
* @param elicitationId The ID of the elicitation to mark as complete.
|
| 164 |
+
* @param options Optional notification options. Useful when the completion notification should be related to a prior request.
|
| 165 |
+
* @returns A function that emits the completion notification when awaited.
|
| 166 |
+
*/
|
| 167 |
+
createElicitationCompletionNotifier(elicitationId: string, options?: NotificationOptions): () => Promise<void>;
|
| 168 |
+
listRoots(params?: ListRootsRequest['params'], options?: RequestOptions): Promise<{
|
| 169 |
+
[x: string]: unknown;
|
| 170 |
+
roots: {
|
| 171 |
+
uri: string;
|
| 172 |
+
name?: string | undefined;
|
| 173 |
+
_meta?: Record<string, unknown> | undefined;
|
| 174 |
+
}[];
|
| 175 |
+
_meta?: {
|
| 176 |
+
[x: string]: unknown;
|
| 177 |
+
progressToken?: string | number | undefined;
|
| 178 |
+
"io.modelcontextprotocol/related-task"?: {
|
| 179 |
+
taskId: string;
|
| 180 |
+
} | undefined;
|
| 181 |
+
} | undefined;
|
| 182 |
+
}>;
|
| 183 |
+
/**
|
| 184 |
+
* Sends a logging message to the client, if connected.
|
| 185 |
+
* Note: You only need to send the parameters object, not the entire JSON RPC message
|
| 186 |
+
* @see LoggingMessageNotification
|
| 187 |
+
* @param params
|
| 188 |
+
* @param sessionId optional for stateless and backward compatibility
|
| 189 |
+
*/
|
| 190 |
+
sendLoggingMessage(params: LoggingMessageNotification['params'], sessionId?: string): Promise<void>;
|
| 191 |
+
sendResourceUpdated(params: ResourceUpdatedNotification['params']): Promise<void>;
|
| 192 |
+
sendResourceListChanged(): Promise<void>;
|
| 193 |
+
sendToolListChanged(): Promise<void>;
|
| 194 |
+
sendPromptListChanged(): Promise<void>;
|
| 195 |
+
}
|
| 196 |
+
//# sourceMappingURL=index.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"index.d.ts","sour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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { mergeCapabilities, Protocol } from '../shared/protocol.js';
|
| 2 |
+
import { CreateMessageResultSchema, CreateMessageResultWithToolsSchema, ElicitResultSchema, EmptyResultSchema, ErrorCode, InitializedNotificationSchema, InitializeRequestSchema, LATEST_PROTOCOL_VERSION, ListRootsResultSchema, LoggingLevelSchema, McpError, SetLevelRequestSchema, SUPPORTED_PROTOCOL_VERSIONS, CallToolRequestSchema, CallToolResultSchema, CreateTaskResultSchema } from '../types.js';
|
| 3 |
+
import { AjvJsonSchemaValidator } from '../validation/ajv-provider.js';
|
| 4 |
+
import { getObjectShape, isZ4Schema, safeParse } from './zod-compat.js';
|
| 5 |
+
import { ExperimentalServerTasks } from '../experimental/tasks/server.js';
|
| 6 |
+
import { assertToolsCallTaskCapability, assertClientRequestTaskCapability } from '../experimental/tasks/helpers.js';
|
| 7 |
+
/**
|
| 8 |
+
* An MCP server on top of a pluggable transport.
|
| 9 |
+
*
|
| 10 |
+
* This server will automatically respond to the initialization flow as initiated from the client.
|
| 11 |
+
*
|
| 12 |
+
* To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters:
|
| 13 |
+
*
|
| 14 |
+
* ```typescript
|
| 15 |
+
* // Custom schemas
|
| 16 |
+
* const CustomRequestSchema = RequestSchema.extend({...})
|
| 17 |
+
* const CustomNotificationSchema = NotificationSchema.extend({...})
|
| 18 |
+
* const CustomResultSchema = ResultSchema.extend({...})
|
| 19 |
+
*
|
| 20 |
+
* // Type aliases
|
| 21 |
+
* type CustomRequest = z.infer<typeof CustomRequestSchema>
|
| 22 |
+
* type CustomNotification = z.infer<typeof CustomNotificationSchema>
|
| 23 |
+
* type CustomResult = z.infer<typeof CustomResultSchema>
|
| 24 |
+
*
|
| 25 |
+
* // Create typed server
|
| 26 |
+
* const server = new Server<CustomRequest, CustomNotification, CustomResult>({
|
| 27 |
+
* name: "CustomServer",
|
| 28 |
+
* version: "1.0.0"
|
| 29 |
+
* })
|
| 30 |
+
* ```
|
| 31 |
+
* @deprecated Use `McpServer` instead for the high-level API. Only use `Server` for advanced use cases.
|
| 32 |
+
*/
|
| 33 |
+
export class Server extends Protocol {
|
| 34 |
+
/**
|
| 35 |
+
* Initializes this server with the given name and version information.
|
| 36 |
+
*/
|
| 37 |
+
constructor(_serverInfo, options) {
|
| 38 |
+
super(options);
|
| 39 |
+
this._serverInfo = _serverInfo;
|
| 40 |
+
// Map log levels by session id
|
| 41 |
+
this._loggingLevels = new Map();
|
| 42 |
+
// Map LogLevelSchema to severity index
|
| 43 |
+
this.LOG_LEVEL_SEVERITY = new Map(LoggingLevelSchema.options.map((level, index) => [level, index]));
|
| 44 |
+
// Is a message with the given level ignored in the log level set for the given session id?
|
| 45 |
+
this.isMessageIgnored = (level, sessionId) => {
|
| 46 |
+
const currentLevel = this._loggingLevels.get(sessionId);
|
| 47 |
+
return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
|
| 48 |
+
};
|
| 49 |
+
this._capabilities = options?.capabilities ?? {};
|
| 50 |
+
this._instructions = options?.instructions;
|
| 51 |
+
this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator();
|
| 52 |
+
this.setRequestHandler(InitializeRequestSchema, request => this._oninitialize(request));
|
| 53 |
+
this.setNotificationHandler(InitializedNotificationSchema, () => this.oninitialized?.());
|
| 54 |
+
if (this._capabilities.logging) {
|
| 55 |
+
this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
|
| 56 |
+
const transportSessionId = extra.sessionId || extra.requestInfo?.headers['mcp-session-id'] || undefined;
|
| 57 |
+
const { level } = request.params;
|
| 58 |
+
const parseResult = LoggingLevelSchema.safeParse(level);
|
| 59 |
+
if (parseResult.success) {
|
| 60 |
+
this._loggingLevels.set(transportSessionId, parseResult.data);
|
| 61 |
+
}
|
| 62 |
+
return {};
|
| 63 |
+
});
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
/**
|
| 67 |
+
* Access experimental features.
|
| 68 |
+
*
|
| 69 |
+
* WARNING: These APIs are experimental and may change without notice.
|
| 70 |
+
*
|
| 71 |
+
* @experimental
|
| 72 |
+
*/
|
| 73 |
+
get experimental() {
|
| 74 |
+
if (!this._experimental) {
|
| 75 |
+
this._experimental = {
|
| 76 |
+
tasks: new ExperimentalServerTasks(this)
|
| 77 |
+
};
|
| 78 |
+
}
|
| 79 |
+
return this._experimental;
|
| 80 |
+
}
|
| 81 |
+
/**
|
| 82 |
+
* Registers new capabilities. This can only be called before connecting to a transport.
|
| 83 |
+
*
|
| 84 |
+
* The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
|
| 85 |
+
*/
|
| 86 |
+
registerCapabilities(capabilities) {
|
| 87 |
+
if (this.transport) {
|
| 88 |
+
throw new Error('Cannot register capabilities after connecting to transport');
|
| 89 |
+
}
|
| 90 |
+
this._capabilities = mergeCapabilities(this._capabilities, capabilities);
|
| 91 |
+
}
|
| 92 |
+
/**
|
| 93 |
+
* Override request handler registration to enforce server-side validation for tools/call.
|
| 94 |
+
*/
|
| 95 |
+
setRequestHandler(requestSchema, handler) {
|
| 96 |
+
const shape = getObjectShape(requestSchema);
|
| 97 |
+
const methodSchema = shape?.method;
|
| 98 |
+
if (!methodSchema) {
|
| 99 |
+
throw new Error('Schema is missing a method literal');
|
| 100 |
+
}
|
| 101 |
+
// Extract literal value using type-safe property access
|
| 102 |
+
let methodValue;
|
| 103 |
+
if (isZ4Schema(methodSchema)) {
|
| 104 |
+
const v4Schema = methodSchema;
|
| 105 |
+
const v4Def = v4Schema._zod?.def;
|
| 106 |
+
methodValue = v4Def?.value ?? v4Schema.value;
|
| 107 |
+
}
|
| 108 |
+
else {
|
| 109 |
+
const v3Schema = methodSchema;
|
| 110 |
+
const legacyDef = v3Schema._def;
|
| 111 |
+
methodValue = legacyDef?.value ?? v3Schema.value;
|
| 112 |
+
}
|
| 113 |
+
if (typeof methodValue !== 'string') {
|
| 114 |
+
throw new Error('Schema method literal must be a string');
|
| 115 |
+
}
|
| 116 |
+
const method = methodValue;
|
| 117 |
+
if (method === 'tools/call') {
|
| 118 |
+
const wrappedHandler = async (request, extra) => {
|
| 119 |
+
const validatedRequest = safeParse(CallToolRequestSchema, request);
|
| 120 |
+
if (!validatedRequest.success) {
|
| 121 |
+
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
| 122 |
+
throw new McpError(ErrorCode.InvalidParams, `Invalid tools/call request: ${errorMessage}`);
|
| 123 |
+
}
|
| 124 |
+
const { params } = validatedRequest.data;
|
| 125 |
+
const result = await Promise.resolve(handler(request, extra));
|
| 126 |
+
// When task creation is requested, validate and return CreateTaskResult
|
| 127 |
+
if (params.task) {
|
| 128 |
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
| 129 |
+
if (!taskValidationResult.success) {
|
| 130 |
+
const errorMessage = taskValidationResult.error instanceof Error
|
| 131 |
+
? taskValidationResult.error.message
|
| 132 |
+
: String(taskValidationResult.error);
|
| 133 |
+
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
| 134 |
+
}
|
| 135 |
+
return taskValidationResult.data;
|
| 136 |
+
}
|
| 137 |
+
// For non-task requests, validate against CallToolResultSchema
|
| 138 |
+
const validationResult = safeParse(CallToolResultSchema, result);
|
| 139 |
+
if (!validationResult.success) {
|
| 140 |
+
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
| 141 |
+
throw new McpError(ErrorCode.InvalidParams, `Invalid tools/call result: ${errorMessage}`);
|
| 142 |
+
}
|
| 143 |
+
return validationResult.data;
|
| 144 |
+
};
|
| 145 |
+
// Install the wrapped handler
|
| 146 |
+
return super.setRequestHandler(requestSchema, wrappedHandler);
|
| 147 |
+
}
|
| 148 |
+
// Other handlers use default behavior
|
| 149 |
+
return super.setRequestHandler(requestSchema, handler);
|
| 150 |
+
}
|
| 151 |
+
assertCapabilityForMethod(method) {
|
| 152 |
+
switch (method) {
|
| 153 |
+
case 'sampling/createMessage':
|
| 154 |
+
if (!this._clientCapabilities?.sampling) {
|
| 155 |
+
throw new Error(`Client does not support sampling (required for ${method})`);
|
| 156 |
+
}
|
| 157 |
+
break;
|
| 158 |
+
case 'elicitation/create':
|
| 159 |
+
if (!this._clientCapabilities?.elicitation) {
|
| 160 |
+
throw new Error(`Client does not support elicitation (required for ${method})`);
|
| 161 |
+
}
|
| 162 |
+
break;
|
| 163 |
+
case 'roots/list':
|
| 164 |
+
if (!this._clientCapabilities?.roots) {
|
| 165 |
+
throw new Error(`Client does not support listing roots (required for ${method})`);
|
| 166 |
+
}
|
| 167 |
+
break;
|
| 168 |
+
case 'ping':
|
| 169 |
+
// No specific capability required for ping
|
| 170 |
+
break;
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
assertNotificationCapability(method) {
|
| 174 |
+
switch (method) {
|
| 175 |
+
case 'notifications/message':
|
| 176 |
+
if (!this._capabilities.logging) {
|
| 177 |
+
throw new Error(`Server does not support logging (required for ${method})`);
|
| 178 |
+
}
|
| 179 |
+
break;
|
| 180 |
+
case 'notifications/resources/updated':
|
| 181 |
+
case 'notifications/resources/list_changed':
|
| 182 |
+
if (!this._capabilities.resources) {
|
| 183 |
+
throw new Error(`Server does not support notifying about resources (required for ${method})`);
|
| 184 |
+
}
|
| 185 |
+
break;
|
| 186 |
+
case 'notifications/tools/list_changed':
|
| 187 |
+
if (!this._capabilities.tools) {
|
| 188 |
+
throw new Error(`Server does not support notifying of tool list changes (required for ${method})`);
|
| 189 |
+
}
|
| 190 |
+
break;
|
| 191 |
+
case 'notifications/prompts/list_changed':
|
| 192 |
+
if (!this._capabilities.prompts) {
|
| 193 |
+
throw new Error(`Server does not support notifying of prompt list changes (required for ${method})`);
|
| 194 |
+
}
|
| 195 |
+
break;
|
| 196 |
+
case 'notifications/elicitation/complete':
|
| 197 |
+
if (!this._clientCapabilities?.elicitation?.url) {
|
| 198 |
+
throw new Error(`Client does not support URL elicitation (required for ${method})`);
|
| 199 |
+
}
|
| 200 |
+
break;
|
| 201 |
+
case 'notifications/cancelled':
|
| 202 |
+
// Cancellation notifications are always allowed
|
| 203 |
+
break;
|
| 204 |
+
case 'notifications/progress':
|
| 205 |
+
// Progress notifications are always allowed
|
| 206 |
+
break;
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
assertRequestHandlerCapability(method) {
|
| 210 |
+
// Task handlers are registered in Protocol constructor before _capabilities is initialized
|
| 211 |
+
// Skip capability check for task methods during initialization
|
| 212 |
+
if (!this._capabilities) {
|
| 213 |
+
return;
|
| 214 |
+
}
|
| 215 |
+
switch (method) {
|
| 216 |
+
case 'completion/complete':
|
| 217 |
+
if (!this._capabilities.completions) {
|
| 218 |
+
throw new Error(`Server does not support completions (required for ${method})`);
|
| 219 |
+
}
|
| 220 |
+
break;
|
| 221 |
+
case 'logging/setLevel':
|
| 222 |
+
if (!this._capabilities.logging) {
|
| 223 |
+
throw new Error(`Server does not support logging (required for ${method})`);
|
| 224 |
+
}
|
| 225 |
+
break;
|
| 226 |
+
case 'prompts/get':
|
| 227 |
+
case 'prompts/list':
|
| 228 |
+
if (!this._capabilities.prompts) {
|
| 229 |
+
throw new Error(`Server does not support prompts (required for ${method})`);
|
| 230 |
+
}
|
| 231 |
+
break;
|
| 232 |
+
case 'resources/list':
|
| 233 |
+
case 'resources/templates/list':
|
| 234 |
+
case 'resources/read':
|
| 235 |
+
if (!this._capabilities.resources) {
|
| 236 |
+
throw new Error(`Server does not support resources (required for ${method})`);
|
| 237 |
+
}
|
| 238 |
+
break;
|
| 239 |
+
case 'tools/call':
|
| 240 |
+
case 'tools/list':
|
| 241 |
+
if (!this._capabilities.tools) {
|
| 242 |
+
throw new Error(`Server does not support tools (required for ${method})`);
|
| 243 |
+
}
|
| 244 |
+
break;
|
| 245 |
+
case 'tasks/get':
|
| 246 |
+
case 'tasks/list':
|
| 247 |
+
case 'tasks/result':
|
| 248 |
+
case 'tasks/cancel':
|
| 249 |
+
if (!this._capabilities.tasks) {
|
| 250 |
+
throw new Error(`Server does not support tasks capability (required for ${method})`);
|
| 251 |
+
}
|
| 252 |
+
break;
|
| 253 |
+
case 'ping':
|
| 254 |
+
case 'initialize':
|
| 255 |
+
// No specific capability required for these methods
|
| 256 |
+
break;
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
assertTaskCapability(method) {
|
| 260 |
+
assertClientRequestTaskCapability(this._clientCapabilities?.tasks?.requests, method, 'Client');
|
| 261 |
+
}
|
| 262 |
+
assertTaskHandlerCapability(method) {
|
| 263 |
+
// Task handlers are registered in Protocol constructor before _capabilities is initialized
|
| 264 |
+
// Skip capability check for task methods during initialization
|
| 265 |
+
if (!this._capabilities) {
|
| 266 |
+
return;
|
| 267 |
+
}
|
| 268 |
+
assertToolsCallTaskCapability(this._capabilities.tasks?.requests, method, 'Server');
|
| 269 |
+
}
|
| 270 |
+
async _oninitialize(request) {
|
| 271 |
+
const requestedVersion = request.params.protocolVersion;
|
| 272 |
+
this._clientCapabilities = request.params.capabilities;
|
| 273 |
+
this._clientVersion = request.params.clientInfo;
|
| 274 |
+
const protocolVersion = SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion) ? requestedVersion : LATEST_PROTOCOL_VERSION;
|
| 275 |
+
return {
|
| 276 |
+
protocolVersion,
|
| 277 |
+
capabilities: this.getCapabilities(),
|
| 278 |
+
serverInfo: this._serverInfo,
|
| 279 |
+
...(this._instructions && { instructions: this._instructions })
|
| 280 |
+
};
|
| 281 |
+
}
|
| 282 |
+
/**
|
| 283 |
+
* After initialization has completed, this will be populated with the client's reported capabilities.
|
| 284 |
+
*/
|
| 285 |
+
getClientCapabilities() {
|
| 286 |
+
return this._clientCapabilities;
|
| 287 |
+
}
|
| 288 |
+
/**
|
| 289 |
+
* After initialization has completed, this will be populated with information about the client's name and version.
|
| 290 |
+
*/
|
| 291 |
+
getClientVersion() {
|
| 292 |
+
return this._clientVersion;
|
| 293 |
+
}
|
| 294 |
+
getCapabilities() {
|
| 295 |
+
return this._capabilities;
|
| 296 |
+
}
|
| 297 |
+
async ping() {
|
| 298 |
+
return this.request({ method: 'ping' }, EmptyResultSchema);
|
| 299 |
+
}
|
| 300 |
+
// Implementation
|
| 301 |
+
async createMessage(params, options) {
|
| 302 |
+
// Capability check - only required when tools/toolChoice are provided
|
| 303 |
+
if (params.tools || params.toolChoice) {
|
| 304 |
+
if (!this._clientCapabilities?.sampling?.tools) {
|
| 305 |
+
throw new Error('Client does not support sampling tools capability.');
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
// Message structure validation - always validate tool_use/tool_result pairs.
|
| 309 |
+
// These may appear even without tools/toolChoice in the current request when
|
| 310 |
+
// a previous sampling request returned tool_use and this is a follow-up with results.
|
| 311 |
+
if (params.messages.length > 0) {
|
| 312 |
+
const lastMessage = params.messages[params.messages.length - 1];
|
| 313 |
+
const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
|
| 314 |
+
const hasToolResults = lastContent.some(c => c.type === 'tool_result');
|
| 315 |
+
const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : undefined;
|
| 316 |
+
const previousContent = previousMessage
|
| 317 |
+
? Array.isArray(previousMessage.content)
|
| 318 |
+
? previousMessage.content
|
| 319 |
+
: [previousMessage.content]
|
| 320 |
+
: [];
|
| 321 |
+
const hasPreviousToolUse = previousContent.some(c => c.type === 'tool_use');
|
| 322 |
+
if (hasToolResults) {
|
| 323 |
+
if (lastContent.some(c => c.type !== 'tool_result')) {
|
| 324 |
+
throw new Error('The last message must contain only tool_result content if any is present');
|
| 325 |
+
}
|
| 326 |
+
if (!hasPreviousToolUse) {
|
| 327 |
+
throw new Error('tool_result blocks are not matching any tool_use from the previous message');
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
if (hasPreviousToolUse) {
|
| 331 |
+
const toolUseIds = new Set(previousContent.filter(c => c.type === 'tool_use').map(c => c.id));
|
| 332 |
+
const toolResultIds = new Set(lastContent.filter(c => c.type === 'tool_result').map(c => c.toolUseId));
|
| 333 |
+
if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every(id => toolResultIds.has(id))) {
|
| 334 |
+
throw new Error('ids of tool_result blocks and tool_use blocks from previous message do not match');
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
}
|
| 338 |
+
// Use different schemas based on whether tools are provided
|
| 339 |
+
if (params.tools) {
|
| 340 |
+
return this.request({ method: 'sampling/createMessage', params }, CreateMessageResultWithToolsSchema, options);
|
| 341 |
+
}
|
| 342 |
+
return this.request({ method: 'sampling/createMessage', params }, CreateMessageResultSchema, options);
|
| 343 |
+
}
|
| 344 |
+
/**
|
| 345 |
+
* Creates an elicitation request for the given parameters.
|
| 346 |
+
* For backwards compatibility, `mode` may be omitted for form requests and will default to `'form'`.
|
| 347 |
+
* @param params The parameters for the elicitation request.
|
| 348 |
+
* @param options Optional request options.
|
| 349 |
+
* @returns The result of the elicitation request.
|
| 350 |
+
*/
|
| 351 |
+
async elicitInput(params, options) {
|
| 352 |
+
const mode = (params.mode ?? 'form');
|
| 353 |
+
switch (mode) {
|
| 354 |
+
case 'url': {
|
| 355 |
+
if (!this._clientCapabilities?.elicitation?.url) {
|
| 356 |
+
throw new Error('Client does not support url elicitation.');
|
| 357 |
+
}
|
| 358 |
+
const urlParams = params;
|
| 359 |
+
return this.request({ method: 'elicitation/create', params: urlParams }, ElicitResultSchema, options);
|
| 360 |
+
}
|
| 361 |
+
case 'form': {
|
| 362 |
+
if (!this._clientCapabilities?.elicitation?.form) {
|
| 363 |
+
throw new Error('Client does not support form elicitation.');
|
| 364 |
+
}
|
| 365 |
+
const formParams = params.mode === 'form' ? params : { ...params, mode: 'form' };
|
| 366 |
+
const result = await this.request({ method: 'elicitation/create', params: formParams }, ElicitResultSchema, options);
|
| 367 |
+
if (result.action === 'accept' && result.content && formParams.requestedSchema) {
|
| 368 |
+
try {
|
| 369 |
+
const validator = this._jsonSchemaValidator.getValidator(formParams.requestedSchema);
|
| 370 |
+
const validationResult = validator(result.content);
|
| 371 |
+
if (!validationResult.valid) {
|
| 372 |
+
throw new McpError(ErrorCode.InvalidParams, `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`);
|
| 373 |
+
}
|
| 374 |
+
}
|
| 375 |
+
catch (error) {
|
| 376 |
+
if (error instanceof McpError) {
|
| 377 |
+
throw error;
|
| 378 |
+
}
|
| 379 |
+
throw new McpError(ErrorCode.InternalError, `Error validating elicitation response: ${error instanceof Error ? error.message : String(error)}`);
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
+
return result;
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
/**
|
| 387 |
+
* Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete`
|
| 388 |
+
* notification for the specified elicitation ID.
|
| 389 |
+
*
|
| 390 |
+
* @param elicitationId The ID of the elicitation to mark as complete.
|
| 391 |
+
* @param options Optional notification options. Useful when the completion notification should be related to a prior request.
|
| 392 |
+
* @returns A function that emits the completion notification when awaited.
|
| 393 |
+
*/
|
| 394 |
+
createElicitationCompletionNotifier(elicitationId, options) {
|
| 395 |
+
if (!this._clientCapabilities?.elicitation?.url) {
|
| 396 |
+
throw new Error('Client does not support URL elicitation (required for notifications/elicitation/complete)');
|
| 397 |
+
}
|
| 398 |
+
return () => this.notification({
|
| 399 |
+
method: 'notifications/elicitation/complete',
|
| 400 |
+
params: {
|
| 401 |
+
elicitationId
|
| 402 |
+
}
|
| 403 |
+
}, options);
|
| 404 |
+
}
|
| 405 |
+
async listRoots(params, options) {
|
| 406 |
+
return this.request({ method: 'roots/list', params }, ListRootsResultSchema, options);
|
| 407 |
+
}
|
| 408 |
+
/**
|
| 409 |
+
* Sends a logging message to the client, if connected.
|
| 410 |
+
* Note: You only need to send the parameters object, not the entire JSON RPC message
|
| 411 |
+
* @see LoggingMessageNotification
|
| 412 |
+
* @param params
|
| 413 |
+
* @param sessionId optional for stateless and backward compatibility
|
| 414 |
+
*/
|
| 415 |
+
async sendLoggingMessage(params, sessionId) {
|
| 416 |
+
if (this._capabilities.logging) {
|
| 417 |
+
if (!this.isMessageIgnored(params.level, sessionId)) {
|
| 418 |
+
return this.notification({ method: 'notifications/message', params });
|
| 419 |
+
}
|
| 420 |
+
}
|
| 421 |
+
}
|
| 422 |
+
async sendResourceUpdated(params) {
|
| 423 |
+
return this.notification({
|
| 424 |
+
method: 'notifications/resources/updated',
|
| 425 |
+
params
|
| 426 |
+
});
|
| 427 |
+
}
|
| 428 |
+
async sendResourceListChanged() {
|
| 429 |
+
return this.notification({
|
| 430 |
+
method: 'notifications/resources/list_changed'
|
| 431 |
+
});
|
| 432 |
+
}
|
| 433 |
+
async sendToolListChanged() {
|
| 434 |
+
return this.notification({ method: 'notifications/tools/list_changed' });
|
| 435 |
+
}
|
| 436 |
+
async sendPromptListChanged() {
|
| 437 |
+
return this.notification({ method: 'notifications/prompts/list_changed' });
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
//# sourceMappingURL=index.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAuE,MAAM,uBAAuB,CAAC;AACzI,OAAO,EAIH,yBAAyB,EAEzB,kCAAkC,EAMlC,kBAAkB,EAClB,iBAAiB,EACjB,SAAS,EAET,6BAA6B,EAE7B,uBAAuB,EAEvB,uBAAuB,EAEvB,qBAAqB,EAErB,kBAAkB,EAElB,QAAQ,EAMR,qBAAqB,EACrB,2BAA2B,EAG3B,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EAIzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,OAAO,EAEH,cAAc,EACd,UAAU,EACV,SAAS,EAIZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,6BAA6B,EAAE,iCAAiC,EAAE,MAAM,kCAAkC,CAAC;AA6CpH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,MAIX,SAAQ,QAA8F;IAapG;;OAEG;IACH,YACY,WAA2B,EACnC,OAAuB;QAEvB,KAAK,CAAC,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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Server, ServerOptions } from './index.js';
|
| 2 |
+
import { AnySchema, AnyObjectSchema, ZodRawShapeCompat, SchemaOutput, ShapeOutput } from './zod-compat.js';
|
| 3 |
+
import { Implementation, CallToolResult, Resource, ListResourcesResult, GetPromptResult, ReadResourceResult, ServerRequest, ServerNotification, ToolAnnotations, LoggingMessageNotification, Result, ToolExecution } from '../types.js';
|
| 4 |
+
import { UriTemplate, Variables } from '../shared/uriTemplate.js';
|
| 5 |
+
import { RequestHandlerExtra } from '../shared/protocol.js';
|
| 6 |
+
import { Transport } from '../shared/transport.js';
|
| 7 |
+
import { ExperimentalMcpServerTasks } from '../experimental/tasks/mcp-server.js';
|
| 8 |
+
import type { ToolTaskHandler } from '../experimental/tasks/interfaces.js';
|
| 9 |
+
/**
|
| 10 |
+
* High-level MCP server that provides a simpler API for working with resources, tools, and prompts.
|
| 11 |
+
* For advanced usage (like sending notifications or setting custom request handlers), use the underlying
|
| 12 |
+
* Server instance available via the `server` property.
|
| 13 |
+
*/
|
| 14 |
+
export declare class McpServer {
|
| 15 |
+
/**
|
| 16 |
+
* The underlying Server instance, useful for advanced operations like sending notifications.
|
| 17 |
+
*/
|
| 18 |
+
readonly server: Server;
|
| 19 |
+
private _registeredResources;
|
| 20 |
+
private _registeredResourceTemplates;
|
| 21 |
+
private _registeredTools;
|
| 22 |
+
private _registeredPrompts;
|
| 23 |
+
private _experimental?;
|
| 24 |
+
constructor(serverInfo: Implementation, options?: ServerOptions);
|
| 25 |
+
/**
|
| 26 |
+
* Access experimental features.
|
| 27 |
+
*
|
| 28 |
+
* WARNING: These APIs are experimental and may change without notice.
|
| 29 |
+
*
|
| 30 |
+
* @experimental
|
| 31 |
+
*/
|
| 32 |
+
get experimental(): {
|
| 33 |
+
tasks: ExperimentalMcpServerTasks;
|
| 34 |
+
};
|
| 35 |
+
/**
|
| 36 |
+
* Attaches to the given transport, starts it, and starts listening for messages.
|
| 37 |
+
*
|
| 38 |
+
* The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
|
| 39 |
+
*/
|
| 40 |
+
connect(transport: Transport): Promise<void>;
|
| 41 |
+
/**
|
| 42 |
+
* Closes the connection.
|
| 43 |
+
*/
|
| 44 |
+
close(): Promise<void>;
|
| 45 |
+
private _toolHandlersInitialized;
|
| 46 |
+
private setToolRequestHandlers;
|
| 47 |
+
/**
|
| 48 |
+
* Creates a tool error result.
|
| 49 |
+
*
|
| 50 |
+
* @param errorMessage - The error message.
|
| 51 |
+
* @returns The tool error result.
|
| 52 |
+
*/
|
| 53 |
+
private createToolError;
|
| 54 |
+
/**
|
| 55 |
+
* Validates tool input arguments against the tool's input schema.
|
| 56 |
+
*/
|
| 57 |
+
private validateToolInput;
|
| 58 |
+
/**
|
| 59 |
+
* Validates tool output against the tool's output schema.
|
| 60 |
+
*/
|
| 61 |
+
private validateToolOutput;
|
| 62 |
+
/**
|
| 63 |
+
* Executes a tool handler (either regular or task-based).
|
| 64 |
+
*/
|
| 65 |
+
private executeToolHandler;
|
| 66 |
+
/**
|
| 67 |
+
* Handles automatic task polling for tools with taskSupport 'optional'.
|
| 68 |
+
*/
|
| 69 |
+
private handleAutomaticTaskPolling;
|
| 70 |
+
private _completionHandlerInitialized;
|
| 71 |
+
private setCompletionRequestHandler;
|
| 72 |
+
private handlePromptCompletion;
|
| 73 |
+
private handleResourceCompletion;
|
| 74 |
+
private _resourceHandlersInitialized;
|
| 75 |
+
private setResourceRequestHandlers;
|
| 76 |
+
private _promptHandlersInitialized;
|
| 77 |
+
private setPromptRequestHandlers;
|
| 78 |
+
/**
|
| 79 |
+
* Registers a resource `name` at a fixed URI, which will use the given callback to respond to read requests.
|
| 80 |
+
* @deprecated Use `registerResource` instead.
|
| 81 |
+
*/
|
| 82 |
+
resource(name: string, uri: string, readCallback: ReadResourceCallback): RegisteredResource;
|
| 83 |
+
/**
|
| 84 |
+
* Registers a resource `name` at a fixed URI with metadata, which will use the given callback to respond to read requests.
|
| 85 |
+
* @deprecated Use `registerResource` instead.
|
| 86 |
+
*/
|
| 87 |
+
resource(name: string, uri: string, metadata: ResourceMetadata, readCallback: ReadResourceCallback): RegisteredResource;
|
| 88 |
+
/**
|
| 89 |
+
* Registers a resource `name` with a template pattern, which will use the given callback to respond to read requests.
|
| 90 |
+
* @deprecated Use `registerResource` instead.
|
| 91 |
+
*/
|
| 92 |
+
resource(name: string, template: ResourceTemplate, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate;
|
| 93 |
+
/**
|
| 94 |
+
* Registers a resource `name` with a template pattern and metadata, which will use the given callback to respond to read requests.
|
| 95 |
+
* @deprecated Use `registerResource` instead.
|
| 96 |
+
*/
|
| 97 |
+
resource(name: string, template: ResourceTemplate, metadata: ResourceMetadata, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate;
|
| 98 |
+
/**
|
| 99 |
+
* Registers a resource with a config object and callback.
|
| 100 |
+
* For static resources, use a URI string. For dynamic resources, use a ResourceTemplate.
|
| 101 |
+
*/
|
| 102 |
+
registerResource(name: string, uriOrTemplate: string, config: ResourceMetadata, readCallback: ReadResourceCallback): RegisteredResource;
|
| 103 |
+
registerResource(name: string, uriOrTemplate: ResourceTemplate, config: ResourceMetadata, readCallback: ReadResourceTemplateCallback): RegisteredResourceTemplate;
|
| 104 |
+
private _createRegisteredResource;
|
| 105 |
+
private _createRegisteredResourceTemplate;
|
| 106 |
+
private _createRegisteredPrompt;
|
| 107 |
+
private _createRegisteredTool;
|
| 108 |
+
/**
|
| 109 |
+
* Registers a zero-argument tool `name`, which will run the given function when the client calls it.
|
| 110 |
+
* @deprecated Use `registerTool` instead.
|
| 111 |
+
*/
|
| 112 |
+
tool(name: string, cb: ToolCallback): RegisteredTool;
|
| 113 |
+
/**
|
| 114 |
+
* Registers a zero-argument tool `name` (with a description) which will run the given function when the client calls it.
|
| 115 |
+
* @deprecated Use `registerTool` instead.
|
| 116 |
+
*/
|
| 117 |
+
tool(name: string, description: string, cb: ToolCallback): RegisteredTool;
|
| 118 |
+
/**
|
| 119 |
+
* Registers a tool taking either a parameter schema for validation or annotations for additional metadata.
|
| 120 |
+
* This unified overload handles both `tool(name, paramsSchema, cb)` and `tool(name, annotations, cb)` cases.
|
| 121 |
+
*
|
| 122 |
+
* Note: We use a union type for the second parameter because TypeScript cannot reliably disambiguate
|
| 123 |
+
* between ToolAnnotations and ZodRawShapeCompat during overload resolution, as both are plain object types.
|
| 124 |
+
* @deprecated Use `registerTool` instead.
|
| 125 |
+
*/
|
| 126 |
+
tool<Args extends ZodRawShapeCompat>(name: string, paramsSchemaOrAnnotations: Args | ToolAnnotations, cb: ToolCallback<Args>): RegisteredTool;
|
| 127 |
+
/**
|
| 128 |
+
* Registers a tool `name` (with a description) taking either parameter schema or annotations.
|
| 129 |
+
* This unified overload handles both `tool(name, description, paramsSchema, cb)` and
|
| 130 |
+
* `tool(name, description, annotations, cb)` cases.
|
| 131 |
+
*
|
| 132 |
+
* Note: We use a union type for the third parameter because TypeScript cannot reliably disambiguate
|
| 133 |
+
* between ToolAnnotations and ZodRawShapeCompat during overload resolution, as both are plain object types.
|
| 134 |
+
* @deprecated Use `registerTool` instead.
|
| 135 |
+
*/
|
| 136 |
+
tool<Args extends ZodRawShapeCompat>(name: string, description: string, paramsSchemaOrAnnotations: Args | ToolAnnotations, cb: ToolCallback<Args>): RegisteredTool;
|
| 137 |
+
/**
|
| 138 |
+
* Registers a tool with both parameter schema and annotations.
|
| 139 |
+
* @deprecated Use `registerTool` instead.
|
| 140 |
+
*/
|
| 141 |
+
tool<Args extends ZodRawShapeCompat>(name: string, paramsSchema: Args, annotations: ToolAnnotations, cb: ToolCallback<Args>): RegisteredTool;
|
| 142 |
+
/**
|
| 143 |
+
* Registers a tool with description, parameter schema, and annotations.
|
| 144 |
+
* @deprecated Use `registerTool` instead.
|
| 145 |
+
*/
|
| 146 |
+
tool<Args extends ZodRawShapeCompat>(name: string, description: string, paramsSchema: Args, annotations: ToolAnnotations, cb: ToolCallback<Args>): RegisteredTool;
|
| 147 |
+
/**
|
| 148 |
+
* Registers a tool with a config object and callback.
|
| 149 |
+
*/
|
| 150 |
+
registerTool<OutputArgs extends ZodRawShapeCompat | AnySchema, InputArgs extends undefined | ZodRawShapeCompat | AnySchema = undefined>(name: string, config: {
|
| 151 |
+
title?: string;
|
| 152 |
+
description?: string;
|
| 153 |
+
inputSchema?: InputArgs;
|
| 154 |
+
outputSchema?: OutputArgs;
|
| 155 |
+
annotations?: ToolAnnotations;
|
| 156 |
+
_meta?: Record<string, unknown>;
|
| 157 |
+
}, cb: ToolCallback<InputArgs>): RegisteredTool;
|
| 158 |
+
/**
|
| 159 |
+
* Registers a zero-argument prompt `name`, which will run the given function when the client calls it.
|
| 160 |
+
* @deprecated Use `registerPrompt` instead.
|
| 161 |
+
*/
|
| 162 |
+
prompt(name: string, cb: PromptCallback): RegisteredPrompt;
|
| 163 |
+
/**
|
| 164 |
+
* Registers a zero-argument prompt `name` (with a description) which will run the given function when the client calls it.
|
| 165 |
+
* @deprecated Use `registerPrompt` instead.
|
| 166 |
+
*/
|
| 167 |
+
prompt(name: string, description: string, cb: PromptCallback): RegisteredPrompt;
|
| 168 |
+
/**
|
| 169 |
+
* Registers a prompt `name` accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments.
|
| 170 |
+
* @deprecated Use `registerPrompt` instead.
|
| 171 |
+
*/
|
| 172 |
+
prompt<Args extends PromptArgsRawShape>(name: string, argsSchema: Args, cb: PromptCallback<Args>): RegisteredPrompt;
|
| 173 |
+
/**
|
| 174 |
+
* Registers a prompt `name` (with a description) accepting the given arguments, which must be an object containing named properties associated with Zod schemas. When the client calls it, the function will be run with the parsed and validated arguments.
|
| 175 |
+
* @deprecated Use `registerPrompt` instead.
|
| 176 |
+
*/
|
| 177 |
+
prompt<Args extends PromptArgsRawShape>(name: string, description: string, argsSchema: Args, cb: PromptCallback<Args>): RegisteredPrompt;
|
| 178 |
+
/**
|
| 179 |
+
* Registers a prompt with a config object and callback.
|
| 180 |
+
*/
|
| 181 |
+
registerPrompt<Args extends PromptArgsRawShape>(name: string, config: {
|
| 182 |
+
title?: string;
|
| 183 |
+
description?: string;
|
| 184 |
+
argsSchema?: Args;
|
| 185 |
+
}, cb: PromptCallback<Args>): RegisteredPrompt;
|
| 186 |
+
/**
|
| 187 |
+
* Checks if the server is connected to a transport.
|
| 188 |
+
* @returns True if the server is connected
|
| 189 |
+
*/
|
| 190 |
+
isConnected(): boolean;
|
| 191 |
+
/**
|
| 192 |
+
* Sends a logging message to the client, if connected.
|
| 193 |
+
* Note: You only need to send the parameters object, not the entire JSON RPC message
|
| 194 |
+
* @see LoggingMessageNotification
|
| 195 |
+
* @param params
|
| 196 |
+
* @param sessionId optional for stateless and backward compatibility
|
| 197 |
+
*/
|
| 198 |
+
sendLoggingMessage(params: LoggingMessageNotification['params'], sessionId?: string): Promise<void>;
|
| 199 |
+
/**
|
| 200 |
+
* Sends a resource list changed event to the client, if connected.
|
| 201 |
+
*/
|
| 202 |
+
sendResourceListChanged(): void;
|
| 203 |
+
/**
|
| 204 |
+
* Sends a tool list changed event to the client, if connected.
|
| 205 |
+
*/
|
| 206 |
+
sendToolListChanged(): void;
|
| 207 |
+
/**
|
| 208 |
+
* Sends a prompt list changed event to the client, if connected.
|
| 209 |
+
*/
|
| 210 |
+
sendPromptListChanged(): void;
|
| 211 |
+
}
|
| 212 |
+
/**
|
| 213 |
+
* A callback to complete one variable within a resource template's URI template.
|
| 214 |
+
*/
|
| 215 |
+
export type CompleteResourceTemplateCallback = (value: string, context?: {
|
| 216 |
+
arguments?: Record<string, string>;
|
| 217 |
+
}) => string[] | Promise<string[]>;
|
| 218 |
+
/**
|
| 219 |
+
* A resource template combines a URI pattern with optional functionality to enumerate
|
| 220 |
+
* all resources matching that pattern.
|
| 221 |
+
*/
|
| 222 |
+
export declare class ResourceTemplate {
|
| 223 |
+
private _callbacks;
|
| 224 |
+
private _uriTemplate;
|
| 225 |
+
constructor(uriTemplate: string | UriTemplate, _callbacks: {
|
| 226 |
+
/**
|
| 227 |
+
* A callback to list all resources matching this template. This is required to specified, even if `undefined`, to avoid accidentally forgetting resource listing.
|
| 228 |
+
*/
|
| 229 |
+
list: ListResourcesCallback | undefined;
|
| 230 |
+
/**
|
| 231 |
+
* An optional callback to autocomplete variables within the URI template. Useful for clients and users to discover possible values.
|
| 232 |
+
*/
|
| 233 |
+
complete?: {
|
| 234 |
+
[variable: string]: CompleteResourceTemplateCallback;
|
| 235 |
+
};
|
| 236 |
+
});
|
| 237 |
+
/**
|
| 238 |
+
* Gets the URI template pattern.
|
| 239 |
+
*/
|
| 240 |
+
get uriTemplate(): UriTemplate;
|
| 241 |
+
/**
|
| 242 |
+
* Gets the list callback, if one was provided.
|
| 243 |
+
*/
|
| 244 |
+
get listCallback(): ListResourcesCallback | undefined;
|
| 245 |
+
/**
|
| 246 |
+
* Gets the callback for completing a specific URI template variable, if one was provided.
|
| 247 |
+
*/
|
| 248 |
+
completeCallback(variable: string): CompleteResourceTemplateCallback | undefined;
|
| 249 |
+
}
|
| 250 |
+
export type BaseToolCallback<SendResultT extends Result, Extra extends RequestHandlerExtra<ServerRequest, ServerNotification>, Args extends undefined | ZodRawShapeCompat | AnySchema> = Args extends ZodRawShapeCompat ? (args: ShapeOutput<Args>, extra: Extra) => SendResultT | Promise<SendResultT> : Args extends AnySchema ? (args: SchemaOutput<Args>, extra: Extra) => SendResultT | Promise<SendResultT> : (extra: Extra) => SendResultT | Promise<SendResultT>;
|
| 251 |
+
/**
|
| 252 |
+
* Callback for a tool handler registered with Server.tool().
|
| 253 |
+
*
|
| 254 |
+
* Parameters will include tool arguments, if applicable, as well as other request handler context.
|
| 255 |
+
*
|
| 256 |
+
* The callback should return:
|
| 257 |
+
* - `structuredContent` if the tool has an outputSchema defined
|
| 258 |
+
* - `content` if the tool does not have an outputSchema
|
| 259 |
+
* - Both fields are optional but typically one should be provided
|
| 260 |
+
*/
|
| 261 |
+
export type ToolCallback<Args extends undefined | ZodRawShapeCompat | AnySchema = undefined> = BaseToolCallback<CallToolResult, RequestHandlerExtra<ServerRequest, ServerNotification>, Args>;
|
| 262 |
+
/**
|
| 263 |
+
* Supertype that can handle both regular tools (simple callback) and task-based tools (task handler object).
|
| 264 |
+
*/
|
| 265 |
+
export type AnyToolHandler<Args extends undefined | ZodRawShapeCompat | AnySchema = undefined> = ToolCallback<Args> | ToolTaskHandler<Args>;
|
| 266 |
+
export type RegisteredTool = {
|
| 267 |
+
title?: string;
|
| 268 |
+
description?: string;
|
| 269 |
+
inputSchema?: AnySchema;
|
| 270 |
+
outputSchema?: AnySchema;
|
| 271 |
+
annotations?: ToolAnnotations;
|
| 272 |
+
execution?: ToolExecution;
|
| 273 |
+
_meta?: Record<string, unknown>;
|
| 274 |
+
handler: AnyToolHandler<undefined | ZodRawShapeCompat>;
|
| 275 |
+
enabled: boolean;
|
| 276 |
+
enable(): void;
|
| 277 |
+
disable(): void;
|
| 278 |
+
update<InputArgs extends ZodRawShapeCompat, OutputArgs extends ZodRawShapeCompat>(updates: {
|
| 279 |
+
name?: string | null;
|
| 280 |
+
title?: string;
|
| 281 |
+
description?: string;
|
| 282 |
+
paramsSchema?: InputArgs;
|
| 283 |
+
outputSchema?: OutputArgs;
|
| 284 |
+
annotations?: ToolAnnotations;
|
| 285 |
+
_meta?: Record<string, unknown>;
|
| 286 |
+
callback?: ToolCallback<InputArgs>;
|
| 287 |
+
enabled?: boolean;
|
| 288 |
+
}): void;
|
| 289 |
+
remove(): void;
|
| 290 |
+
};
|
| 291 |
+
/**
|
| 292 |
+
* Additional, optional information for annotating a resource.
|
| 293 |
+
*/
|
| 294 |
+
export type ResourceMetadata = Omit<Resource, 'uri' | 'name'>;
|
| 295 |
+
/**
|
| 296 |
+
* Callback to list all resources matching a given template.
|
| 297 |
+
*/
|
| 298 |
+
export type ListResourcesCallback = (extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => ListResourcesResult | Promise<ListResourcesResult>;
|
| 299 |
+
/**
|
| 300 |
+
* Callback to read a resource at a given URI.
|
| 301 |
+
*/
|
| 302 |
+
export type ReadResourceCallback = (uri: URL, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => ReadResourceResult | Promise<ReadResourceResult>;
|
| 303 |
+
export type RegisteredResource = {
|
| 304 |
+
name: string;
|
| 305 |
+
title?: string;
|
| 306 |
+
metadata?: ResourceMetadata;
|
| 307 |
+
readCallback: ReadResourceCallback;
|
| 308 |
+
enabled: boolean;
|
| 309 |
+
enable(): void;
|
| 310 |
+
disable(): void;
|
| 311 |
+
update(updates: {
|
| 312 |
+
name?: string;
|
| 313 |
+
title?: string;
|
| 314 |
+
uri?: string | null;
|
| 315 |
+
metadata?: ResourceMetadata;
|
| 316 |
+
callback?: ReadResourceCallback;
|
| 317 |
+
enabled?: boolean;
|
| 318 |
+
}): void;
|
| 319 |
+
remove(): void;
|
| 320 |
+
};
|
| 321 |
+
/**
|
| 322 |
+
* Callback to read a resource at a given URI, following a filled-in URI template.
|
| 323 |
+
*/
|
| 324 |
+
export type ReadResourceTemplateCallback = (uri: URL, variables: Variables, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => ReadResourceResult | Promise<ReadResourceResult>;
|
| 325 |
+
export type RegisteredResourceTemplate = {
|
| 326 |
+
resourceTemplate: ResourceTemplate;
|
| 327 |
+
title?: string;
|
| 328 |
+
metadata?: ResourceMetadata;
|
| 329 |
+
readCallback: ReadResourceTemplateCallback;
|
| 330 |
+
enabled: boolean;
|
| 331 |
+
enable(): void;
|
| 332 |
+
disable(): void;
|
| 333 |
+
update(updates: {
|
| 334 |
+
name?: string | null;
|
| 335 |
+
title?: string;
|
| 336 |
+
template?: ResourceTemplate;
|
| 337 |
+
metadata?: ResourceMetadata;
|
| 338 |
+
callback?: ReadResourceTemplateCallback;
|
| 339 |
+
enabled?: boolean;
|
| 340 |
+
}): void;
|
| 341 |
+
remove(): void;
|
| 342 |
+
};
|
| 343 |
+
type PromptArgsRawShape = ZodRawShapeCompat;
|
| 344 |
+
export type PromptCallback<Args extends undefined | PromptArgsRawShape = undefined> = Args extends PromptArgsRawShape ? (args: ShapeOutput<Args>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => GetPromptResult | Promise<GetPromptResult> : (extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => GetPromptResult | Promise<GetPromptResult>;
|
| 345 |
+
export type RegisteredPrompt = {
|
| 346 |
+
title?: string;
|
| 347 |
+
description?: string;
|
| 348 |
+
argsSchema?: AnyObjectSchema;
|
| 349 |
+
callback: PromptCallback<undefined | PromptArgsRawShape>;
|
| 350 |
+
enabled: boolean;
|
| 351 |
+
enable(): void;
|
| 352 |
+
disable(): void;
|
| 353 |
+
update<Args extends PromptArgsRawShape>(updates: {
|
| 354 |
+
name?: string | null;
|
| 355 |
+
title?: string;
|
| 356 |
+
description?: string;
|
| 357 |
+
argsSchema?: Args;
|
| 358 |
+
callback?: PromptCallback<Args>;
|
| 359 |
+
enabled?: boolean;
|
| 360 |
+
}): void;
|
| 361 |
+
remove(): void;
|
| 362 |
+
};
|
| 363 |
+
export {};
|
| 364 |
+
//# sourceMappingURL=mcp.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/server/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACH,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,WAAW,EASd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACH,cAAc,EAGd,cAAc,EAOd,QAAQ,EACR,mBAAmB,EAYnB,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,0BAA0B,EAE1B,MAAM,EAMN,aAAa,EAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAG3E;;;;GAIG;AACH,qBAAa,SAAS;IAClB;;OAEG;IACH,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,oBAAoB,CAA6C;IACzE,OAAO,CAAC,4BAA4B,CAE7B;IACP,OAAO,CAAC,gBAAgB,CAA0C;IAClE,OAAO,CAAC,kBAAkB,CAA4C;IACtE,OAAO,CAAC,aAAa,CA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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Server } from './index.js';
|
| 2 |
+
import { normalizeObjectSchema, safeParseAsync, getObjectShape, objectFromShape, getParseErrorMessage, getSchemaDescription, isSchemaOptional, getLiteralValue } from './zod-compat.js';
|
| 3 |
+
import { toJsonSchemaCompat } from './zod-json-schema-compat.js';
|
| 4 |
+
import { McpError, ErrorCode, ListResourceTemplatesRequestSchema, ReadResourceRequestSchema, ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, CompleteRequestSchema, assertCompleteRequestPrompt, assertCompleteRequestResourceTemplate } from '../types.js';
|
| 5 |
+
import { isCompletable, getCompleter } from './completable.js';
|
| 6 |
+
import { UriTemplate } from '../shared/uriTemplate.js';
|
| 7 |
+
import { validateAndWarnToolName } from '../shared/toolNameValidation.js';
|
| 8 |
+
import { ExperimentalMcpServerTasks } from '../experimental/tasks/mcp-server.js';
|
| 9 |
+
import { ZodOptional } from 'zod';
|
| 10 |
+
/**
|
| 11 |
+
* High-level MCP server that provides a simpler API for working with resources, tools, and prompts.
|
| 12 |
+
* For advanced usage (like sending notifications or setting custom request handlers), use the underlying
|
| 13 |
+
* Server instance available via the `server` property.
|
| 14 |
+
*/
|
| 15 |
+
export class McpServer {
|
| 16 |
+
constructor(serverInfo, options) {
|
| 17 |
+
this._registeredResources = {};
|
| 18 |
+
this._registeredResourceTemplates = {};
|
| 19 |
+
this._registeredTools = {};
|
| 20 |
+
this._registeredPrompts = {};
|
| 21 |
+
this._toolHandlersInitialized = false;
|
| 22 |
+
this._completionHandlerInitialized = false;
|
| 23 |
+
this._resourceHandlersInitialized = false;
|
| 24 |
+
this._promptHandlersInitialized = false;
|
| 25 |
+
this.server = new Server(serverInfo, options);
|
| 26 |
+
}
|
| 27 |
+
/**
|
| 28 |
+
* Access experimental features.
|
| 29 |
+
*
|
| 30 |
+
* WARNING: These APIs are experimental and may change without notice.
|
| 31 |
+
*
|
| 32 |
+
* @experimental
|
| 33 |
+
*/
|
| 34 |
+
get experimental() {
|
| 35 |
+
if (!this._experimental) {
|
| 36 |
+
this._experimental = {
|
| 37 |
+
tasks: new ExperimentalMcpServerTasks(this)
|
| 38 |
+
};
|
| 39 |
+
}
|
| 40 |
+
return this._experimental;
|
| 41 |
+
}
|
| 42 |
+
/**
|
| 43 |
+
* Attaches to the given transport, starts it, and starts listening for messages.
|
| 44 |
+
*
|
| 45 |
+
* The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
|
| 46 |
+
*/
|
| 47 |
+
async connect(transport) {
|
| 48 |
+
return await this.server.connect(transport);
|
| 49 |
+
}
|
| 50 |
+
/**
|
| 51 |
+
* Closes the connection.
|
| 52 |
+
*/
|
| 53 |
+
async close() {
|
| 54 |
+
await this.server.close();
|
| 55 |
+
}
|
| 56 |
+
setToolRequestHandlers() {
|
| 57 |
+
if (this._toolHandlersInitialized) {
|
| 58 |
+
return;
|
| 59 |
+
}
|
| 60 |
+
this.server.assertCanSetRequestHandler(getMethodValue(ListToolsRequestSchema));
|
| 61 |
+
this.server.assertCanSetRequestHandler(getMethodValue(CallToolRequestSchema));
|
| 62 |
+
this.server.registerCapabilities({
|
| 63 |
+
tools: {
|
| 64 |
+
listChanged: true
|
| 65 |
+
}
|
| 66 |
+
});
|
| 67 |
+
this.server.setRequestHandler(ListToolsRequestSchema, () => ({
|
| 68 |
+
tools: Object.entries(this._registeredTools)
|
| 69 |
+
.filter(([, tool]) => tool.enabled)
|
| 70 |
+
.map(([name, tool]) => {
|
| 71 |
+
const toolDefinition = {
|
| 72 |
+
name,
|
| 73 |
+
title: tool.title,
|
| 74 |
+
description: tool.description,
|
| 75 |
+
inputSchema: (() => {
|
| 76 |
+
const obj = normalizeObjectSchema(tool.inputSchema);
|
| 77 |
+
return obj
|
| 78 |
+
? toJsonSchemaCompat(obj, {
|
| 79 |
+
strictUnions: true,
|
| 80 |
+
pipeStrategy: 'input'
|
| 81 |
+
})
|
| 82 |
+
: EMPTY_OBJECT_JSON_SCHEMA;
|
| 83 |
+
})(),
|
| 84 |
+
annotations: tool.annotations,
|
| 85 |
+
execution: tool.execution,
|
| 86 |
+
_meta: tool._meta
|
| 87 |
+
};
|
| 88 |
+
if (tool.outputSchema) {
|
| 89 |
+
const obj = normalizeObjectSchema(tool.outputSchema);
|
| 90 |
+
if (obj) {
|
| 91 |
+
toolDefinition.outputSchema = toJsonSchemaCompat(obj, {
|
| 92 |
+
strictUnions: true,
|
| 93 |
+
pipeStrategy: 'output'
|
| 94 |
+
});
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
return toolDefinition;
|
| 98 |
+
})
|
| 99 |
+
}));
|
| 100 |
+
this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
| 101 |
+
try {
|
| 102 |
+
const tool = this._registeredTools[request.params.name];
|
| 103 |
+
if (!tool) {
|
| 104 |
+
throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} not found`);
|
| 105 |
+
}
|
| 106 |
+
if (!tool.enabled) {
|
| 107 |
+
throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
|
| 108 |
+
}
|
| 109 |
+
const isTaskRequest = !!request.params.task;
|
| 110 |
+
const taskSupport = tool.execution?.taskSupport;
|
| 111 |
+
const isTaskHandler = 'createTask' in tool.handler;
|
| 112 |
+
// Validate task hint configuration
|
| 113 |
+
if ((taskSupport === 'required' || taskSupport === 'optional') && !isTaskHandler) {
|
| 114 |
+
throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has taskSupport '${taskSupport}' but was not registered with registerToolTask`);
|
| 115 |
+
}
|
| 116 |
+
// Handle taskSupport 'required' without task augmentation
|
| 117 |
+
if (taskSupport === 'required' && !isTaskRequest) {
|
| 118 |
+
throw new McpError(ErrorCode.MethodNotFound, `Tool ${request.params.name} requires task augmentation (taskSupport: 'required')`);
|
| 119 |
+
}
|
| 120 |
+
// Handle taskSupport 'optional' without task augmentation - automatic polling
|
| 121 |
+
if (taskSupport === 'optional' && !isTaskRequest && isTaskHandler) {
|
| 122 |
+
return await this.handleAutomaticTaskPolling(tool, request, extra);
|
| 123 |
+
}
|
| 124 |
+
// Normal execution path
|
| 125 |
+
const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
|
| 126 |
+
const result = await this.executeToolHandler(tool, args, extra);
|
| 127 |
+
// Return CreateTaskResult immediately for task requests
|
| 128 |
+
if (isTaskRequest) {
|
| 129 |
+
return result;
|
| 130 |
+
}
|
| 131 |
+
// Validate output schema for non-task requests
|
| 132 |
+
await this.validateToolOutput(tool, result, request.params.name);
|
| 133 |
+
return result;
|
| 134 |
+
}
|
| 135 |
+
catch (error) {
|
| 136 |
+
if (error instanceof McpError) {
|
| 137 |
+
if (error.code === ErrorCode.UrlElicitationRequired) {
|
| 138 |
+
throw error; // Return the error to the caller without wrapping in CallToolResult
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
return this.createToolError(error instanceof Error ? error.message : String(error));
|
| 142 |
+
}
|
| 143 |
+
});
|
| 144 |
+
this._toolHandlersInitialized = true;
|
| 145 |
+
}
|
| 146 |
+
/**
|
| 147 |
+
* Creates a tool error result.
|
| 148 |
+
*
|
| 149 |
+
* @param errorMessage - The error message.
|
| 150 |
+
* @returns The tool error result.
|
| 151 |
+
*/
|
| 152 |
+
createToolError(errorMessage) {
|
| 153 |
+
return {
|
| 154 |
+
content: [
|
| 155 |
+
{
|
| 156 |
+
type: 'text',
|
| 157 |
+
text: errorMessage
|
| 158 |
+
}
|
| 159 |
+
],
|
| 160 |
+
isError: true
|
| 161 |
+
};
|
| 162 |
+
}
|
| 163 |
+
/**
|
| 164 |
+
* Validates tool input arguments against the tool's input schema.
|
| 165 |
+
*/
|
| 166 |
+
async validateToolInput(tool, args, toolName) {
|
| 167 |
+
if (!tool.inputSchema) {
|
| 168 |
+
return undefined;
|
| 169 |
+
}
|
| 170 |
+
// Try to normalize to object schema first (for raw shapes and object schemas)
|
| 171 |
+
// If that fails, use the schema directly (for union/intersection/etc)
|
| 172 |
+
const inputObj = normalizeObjectSchema(tool.inputSchema);
|
| 173 |
+
const schemaToParse = inputObj ?? tool.inputSchema;
|
| 174 |
+
const parseResult = await safeParseAsync(schemaToParse, args);
|
| 175 |
+
if (!parseResult.success) {
|
| 176 |
+
const error = 'error' in parseResult ? parseResult.error : 'Unknown error';
|
| 177 |
+
const errorMessage = getParseErrorMessage(error);
|
| 178 |
+
throw new McpError(ErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName}: ${errorMessage}`);
|
| 179 |
+
}
|
| 180 |
+
return parseResult.data;
|
| 181 |
+
}
|
| 182 |
+
/**
|
| 183 |
+
* Validates tool output against the tool's output schema.
|
| 184 |
+
*/
|
| 185 |
+
async validateToolOutput(tool, result, toolName) {
|
| 186 |
+
if (!tool.outputSchema) {
|
| 187 |
+
return;
|
| 188 |
+
}
|
| 189 |
+
// Only validate CallToolResult, not CreateTaskResult
|
| 190 |
+
if (!('content' in result)) {
|
| 191 |
+
return;
|
| 192 |
+
}
|
| 193 |
+
if (result.isError) {
|
| 194 |
+
return;
|
| 195 |
+
}
|
| 196 |
+
if (!result.structuredContent) {
|
| 197 |
+
throw new McpError(ErrorCode.InvalidParams, `Output validation error: Tool ${toolName} has an output schema but no structured content was provided`);
|
| 198 |
+
}
|
| 199 |
+
// if the tool has an output schema, validate structured content
|
| 200 |
+
const outputObj = normalizeObjectSchema(tool.outputSchema);
|
| 201 |
+
const parseResult = await safeParseAsync(outputObj, result.structuredContent);
|
| 202 |
+
if (!parseResult.success) {
|
| 203 |
+
const error = 'error' in parseResult ? parseResult.error : 'Unknown error';
|
| 204 |
+
const errorMessage = getParseErrorMessage(error);
|
| 205 |
+
throw new McpError(ErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName}: ${errorMessage}`);
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
/**
|
| 209 |
+
* Executes a tool handler (either regular or task-based).
|
| 210 |
+
*/
|
| 211 |
+
async executeToolHandler(tool, args, extra) {
|
| 212 |
+
const handler = tool.handler;
|
| 213 |
+
const isTaskHandler = 'createTask' in handler;
|
| 214 |
+
if (isTaskHandler) {
|
| 215 |
+
if (!extra.taskStore) {
|
| 216 |
+
throw new Error('No task store provided.');
|
| 217 |
+
}
|
| 218 |
+
const taskExtra = { ...extra, taskStore: extra.taskStore };
|
| 219 |
+
if (tool.inputSchema) {
|
| 220 |
+
const typedHandler = handler;
|
| 221 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 222 |
+
return await Promise.resolve(typedHandler.createTask(args, taskExtra));
|
| 223 |
+
}
|
| 224 |
+
else {
|
| 225 |
+
const typedHandler = handler;
|
| 226 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 227 |
+
return await Promise.resolve(typedHandler.createTask(taskExtra));
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
if (tool.inputSchema) {
|
| 231 |
+
const typedHandler = handler;
|
| 232 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 233 |
+
return await Promise.resolve(typedHandler(args, extra));
|
| 234 |
+
}
|
| 235 |
+
else {
|
| 236 |
+
const typedHandler = handler;
|
| 237 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 238 |
+
return await Promise.resolve(typedHandler(extra));
|
| 239 |
+
}
|
| 240 |
+
}
|
| 241 |
+
/**
|
| 242 |
+
* Handles automatic task polling for tools with taskSupport 'optional'.
|
| 243 |
+
*/
|
| 244 |
+
async handleAutomaticTaskPolling(tool, request, extra) {
|
| 245 |
+
if (!extra.taskStore) {
|
| 246 |
+
throw new Error('No task store provided for task-capable tool.');
|
| 247 |
+
}
|
| 248 |
+
// Validate input and create task
|
| 249 |
+
const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
|
| 250 |
+
const handler = tool.handler;
|
| 251 |
+
const taskExtra = { ...extra, taskStore: extra.taskStore };
|
| 252 |
+
const createTaskResult = args // undefined only if tool.inputSchema is undefined
|
| 253 |
+
? await Promise.resolve(handler.createTask(args, taskExtra))
|
| 254 |
+
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 255 |
+
await Promise.resolve(handler.createTask(taskExtra));
|
| 256 |
+
// Poll until completion
|
| 257 |
+
const taskId = createTaskResult.task.taskId;
|
| 258 |
+
let task = createTaskResult.task;
|
| 259 |
+
const pollInterval = task.pollInterval ?? 5000;
|
| 260 |
+
while (task.status !== 'completed' && task.status !== 'failed' && task.status !== 'cancelled') {
|
| 261 |
+
await new Promise(resolve => setTimeout(resolve, pollInterval));
|
| 262 |
+
const updatedTask = await extra.taskStore.getTask(taskId);
|
| 263 |
+
if (!updatedTask) {
|
| 264 |
+
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
| 265 |
+
}
|
| 266 |
+
task = updatedTask;
|
| 267 |
+
}
|
| 268 |
+
// Return the final result
|
| 269 |
+
return (await extra.taskStore.getTaskResult(taskId));
|
| 270 |
+
}
|
| 271 |
+
setCompletionRequestHandler() {
|
| 272 |
+
if (this._completionHandlerInitialized) {
|
| 273 |
+
return;
|
| 274 |
+
}
|
| 275 |
+
this.server.assertCanSetRequestHandler(getMethodValue(CompleteRequestSchema));
|
| 276 |
+
this.server.registerCapabilities({
|
| 277 |
+
completions: {}
|
| 278 |
+
});
|
| 279 |
+
this.server.setRequestHandler(CompleteRequestSchema, async (request) => {
|
| 280 |
+
switch (request.params.ref.type) {
|
| 281 |
+
case 'ref/prompt':
|
| 282 |
+
assertCompleteRequestPrompt(request);
|
| 283 |
+
return this.handlePromptCompletion(request, request.params.ref);
|
| 284 |
+
case 'ref/resource':
|
| 285 |
+
assertCompleteRequestResourceTemplate(request);
|
| 286 |
+
return this.handleResourceCompletion(request, request.params.ref);
|
| 287 |
+
default:
|
| 288 |
+
throw new McpError(ErrorCode.InvalidParams, `Invalid completion reference: ${request.params.ref}`);
|
| 289 |
+
}
|
| 290 |
+
});
|
| 291 |
+
this._completionHandlerInitialized = true;
|
| 292 |
+
}
|
| 293 |
+
async handlePromptCompletion(request, ref) {
|
| 294 |
+
const prompt = this._registeredPrompts[ref.name];
|
| 295 |
+
if (!prompt) {
|
| 296 |
+
throw new McpError(ErrorCode.InvalidParams, `Prompt ${ref.name} not found`);
|
| 297 |
+
}
|
| 298 |
+
if (!prompt.enabled) {
|
| 299 |
+
throw new McpError(ErrorCode.InvalidParams, `Prompt ${ref.name} disabled`);
|
| 300 |
+
}
|
| 301 |
+
if (!prompt.argsSchema) {
|
| 302 |
+
return EMPTY_COMPLETION_RESULT;
|
| 303 |
+
}
|
| 304 |
+
const promptShape = getObjectShape(prompt.argsSchema);
|
| 305 |
+
const field = promptShape?.[request.params.argument.name];
|
| 306 |
+
if (!isCompletable(field)) {
|
| 307 |
+
return EMPTY_COMPLETION_RESULT;
|
| 308 |
+
}
|
| 309 |
+
const completer = getCompleter(field);
|
| 310 |
+
if (!completer) {
|
| 311 |
+
return EMPTY_COMPLETION_RESULT;
|
| 312 |
+
}
|
| 313 |
+
const suggestions = await completer(request.params.argument.value, request.params.context);
|
| 314 |
+
return createCompletionResult(suggestions);
|
| 315 |
+
}
|
| 316 |
+
async handleResourceCompletion(request, ref) {
|
| 317 |
+
const template = Object.values(this._registeredResourceTemplates).find(t => t.resourceTemplate.uriTemplate.toString() === ref.uri);
|
| 318 |
+
if (!template) {
|
| 319 |
+
if (this._registeredResources[ref.uri]) {
|
| 320 |
+
// Attempting to autocomplete a fixed resource URI is not an error in the spec (but probably should be).
|
| 321 |
+
return EMPTY_COMPLETION_RESULT;
|
| 322 |
+
}
|
| 323 |
+
throw new McpError(ErrorCode.InvalidParams, `Resource template ${request.params.ref.uri} not found`);
|
| 324 |
+
}
|
| 325 |
+
const completer = template.resourceTemplate.completeCallback(request.params.argument.name);
|
| 326 |
+
if (!completer) {
|
| 327 |
+
return EMPTY_COMPLETION_RESULT;
|
| 328 |
+
}
|
| 329 |
+
const suggestions = await completer(request.params.argument.value, request.params.context);
|
| 330 |
+
return createCompletionResult(suggestions);
|
| 331 |
+
}
|
| 332 |
+
setResourceRequestHandlers() {
|
| 333 |
+
if (this._resourceHandlersInitialized) {
|
| 334 |
+
return;
|
| 335 |
+
}
|
| 336 |
+
this.server.assertCanSetRequestHandler(getMethodValue(ListResourcesRequestSchema));
|
| 337 |
+
this.server.assertCanSetRequestHandler(getMethodValue(ListResourceTemplatesRequestSchema));
|
| 338 |
+
this.server.assertCanSetRequestHandler(getMethodValue(ReadResourceRequestSchema));
|
| 339 |
+
this.server.registerCapabilities({
|
| 340 |
+
resources: {
|
| 341 |
+
listChanged: true
|
| 342 |
+
}
|
| 343 |
+
});
|
| 344 |
+
this.server.setRequestHandler(ListResourcesRequestSchema, async (request, extra) => {
|
| 345 |
+
const resources = Object.entries(this._registeredResources)
|
| 346 |
+
.filter(([_, resource]) => resource.enabled)
|
| 347 |
+
.map(([uri, resource]) => ({
|
| 348 |
+
uri,
|
| 349 |
+
name: resource.name,
|
| 350 |
+
...resource.metadata
|
| 351 |
+
}));
|
| 352 |
+
const templateResources = [];
|
| 353 |
+
for (const template of Object.values(this._registeredResourceTemplates)) {
|
| 354 |
+
if (!template.resourceTemplate.listCallback) {
|
| 355 |
+
continue;
|
| 356 |
+
}
|
| 357 |
+
const result = await template.resourceTemplate.listCallback(extra);
|
| 358 |
+
for (const resource of result.resources) {
|
| 359 |
+
templateResources.push({
|
| 360 |
+
...template.metadata,
|
| 361 |
+
// the defined resource metadata should override the template metadata if present
|
| 362 |
+
...resource
|
| 363 |
+
});
|
| 364 |
+
}
|
| 365 |
+
}
|
| 366 |
+
return { resources: [...resources, ...templateResources] };
|
| 367 |
+
});
|
| 368 |
+
this.server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => {
|
| 369 |
+
const resourceTemplates = Object.entries(this._registeredResourceTemplates).map(([name, template]) => ({
|
| 370 |
+
name,
|
| 371 |
+
uriTemplate: template.resourceTemplate.uriTemplate.toString(),
|
| 372 |
+
...template.metadata
|
| 373 |
+
}));
|
| 374 |
+
return { resourceTemplates };
|
| 375 |
+
});
|
| 376 |
+
this.server.setRequestHandler(ReadResourceRequestSchema, async (request, extra) => {
|
| 377 |
+
const uri = new URL(request.params.uri);
|
| 378 |
+
// First check for exact resource match
|
| 379 |
+
const resource = this._registeredResources[uri.toString()];
|
| 380 |
+
if (resource) {
|
| 381 |
+
if (!resource.enabled) {
|
| 382 |
+
throw new McpError(ErrorCode.InvalidParams, `Resource ${uri} disabled`);
|
| 383 |
+
}
|
| 384 |
+
return resource.readCallback(uri, extra);
|
| 385 |
+
}
|
| 386 |
+
// Then check templates
|
| 387 |
+
for (const template of Object.values(this._registeredResourceTemplates)) {
|
| 388 |
+
const variables = template.resourceTemplate.uriTemplate.match(uri.toString());
|
| 389 |
+
if (variables) {
|
| 390 |
+
return template.readCallback(uri, variables, extra);
|
| 391 |
+
}
|
| 392 |
+
}
|
| 393 |
+
throw new McpError(ErrorCode.InvalidParams, `Resource ${uri} not found`);
|
| 394 |
+
});
|
| 395 |
+
this._resourceHandlersInitialized = true;
|
| 396 |
+
}
|
| 397 |
+
setPromptRequestHandlers() {
|
| 398 |
+
if (this._promptHandlersInitialized) {
|
| 399 |
+
return;
|
| 400 |
+
}
|
| 401 |
+
this.server.assertCanSetRequestHandler(getMethodValue(ListPromptsRequestSchema));
|
| 402 |
+
this.server.assertCanSetRequestHandler(getMethodValue(GetPromptRequestSchema));
|
| 403 |
+
this.server.registerCapabilities({
|
| 404 |
+
prompts: {
|
| 405 |
+
listChanged: true
|
| 406 |
+
}
|
| 407 |
+
});
|
| 408 |
+
this.server.setRequestHandler(ListPromptsRequestSchema, () => ({
|
| 409 |
+
prompts: Object.entries(this._registeredPrompts)
|
| 410 |
+
.filter(([, prompt]) => prompt.enabled)
|
| 411 |
+
.map(([name, prompt]) => {
|
| 412 |
+
return {
|
| 413 |
+
name,
|
| 414 |
+
title: prompt.title,
|
| 415 |
+
description: prompt.description,
|
| 416 |
+
arguments: prompt.argsSchema ? promptArgumentsFromSchema(prompt.argsSchema) : undefined
|
| 417 |
+
};
|
| 418 |
+
})
|
| 419 |
+
}));
|
| 420 |
+
this.server.setRequestHandler(GetPromptRequestSchema, async (request, extra) => {
|
| 421 |
+
const prompt = this._registeredPrompts[request.params.name];
|
| 422 |
+
if (!prompt) {
|
| 423 |
+
throw new McpError(ErrorCode.InvalidParams, `Prompt ${request.params.name} not found`);
|
| 424 |
+
}
|
| 425 |
+
if (!prompt.enabled) {
|
| 426 |
+
throw new McpError(ErrorCode.InvalidParams, `Prompt ${request.params.name} disabled`);
|
| 427 |
+
}
|
| 428 |
+
if (prompt.argsSchema) {
|
| 429 |
+
const argsObj = normalizeObjectSchema(prompt.argsSchema);
|
| 430 |
+
const parseResult = await safeParseAsync(argsObj, request.params.arguments);
|
| 431 |
+
if (!parseResult.success) {
|
| 432 |
+
const error = 'error' in parseResult ? parseResult.error : 'Unknown error';
|
| 433 |
+
const errorMessage = getParseErrorMessage(error);
|
| 434 |
+
throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for prompt ${request.params.name}: ${errorMessage}`);
|
| 435 |
+
}
|
| 436 |
+
const args = parseResult.data;
|
| 437 |
+
const cb = prompt.callback;
|
| 438 |
+
return await Promise.resolve(cb(args, extra));
|
| 439 |
+
}
|
| 440 |
+
else {
|
| 441 |
+
const cb = prompt.callback;
|
| 442 |
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 443 |
+
return await Promise.resolve(cb(extra));
|
| 444 |
+
}
|
| 445 |
+
});
|
| 446 |
+
this._promptHandlersInitialized = true;
|
| 447 |
+
}
|
| 448 |
+
resource(name, uriOrTemplate, ...rest) {
|
| 449 |
+
let metadata;
|
| 450 |
+
if (typeof rest[0] === 'object') {
|
| 451 |
+
metadata = rest.shift();
|
| 452 |
+
}
|
| 453 |
+
const readCallback = rest[0];
|
| 454 |
+
if (typeof uriOrTemplate === 'string') {
|
| 455 |
+
if (this._registeredResources[uriOrTemplate]) {
|
| 456 |
+
throw new Error(`Resource ${uriOrTemplate} is already registered`);
|
| 457 |
+
}
|
| 458 |
+
const registeredResource = this._createRegisteredResource(name, undefined, uriOrTemplate, metadata, readCallback);
|
| 459 |
+
this.setResourceRequestHandlers();
|
| 460 |
+
this.sendResourceListChanged();
|
| 461 |
+
return registeredResource;
|
| 462 |
+
}
|
| 463 |
+
else {
|
| 464 |
+
if (this._registeredResourceTemplates[name]) {
|
| 465 |
+
throw new Error(`Resource template ${name} is already registered`);
|
| 466 |
+
}
|
| 467 |
+
const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, undefined, uriOrTemplate, metadata, readCallback);
|
| 468 |
+
this.setResourceRequestHandlers();
|
| 469 |
+
this.sendResourceListChanged();
|
| 470 |
+
return registeredResourceTemplate;
|
| 471 |
+
}
|
| 472 |
+
}
|
| 473 |
+
registerResource(name, uriOrTemplate, config, readCallback) {
|
| 474 |
+
if (typeof uriOrTemplate === 'string') {
|
| 475 |
+
if (this._registeredResources[uriOrTemplate]) {
|
| 476 |
+
throw new Error(`Resource ${uriOrTemplate} is already registered`);
|
| 477 |
+
}
|
| 478 |
+
const registeredResource = this._createRegisteredResource(name, config.title, uriOrTemplate, config, readCallback);
|
| 479 |
+
this.setResourceRequestHandlers();
|
| 480 |
+
this.sendResourceListChanged();
|
| 481 |
+
return registeredResource;
|
| 482 |
+
}
|
| 483 |
+
else {
|
| 484 |
+
if (this._registeredResourceTemplates[name]) {
|
| 485 |
+
throw new Error(`Resource template ${name} is already registered`);
|
| 486 |
+
}
|
| 487 |
+
const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, config.title, uriOrTemplate, config, readCallback);
|
| 488 |
+
this.setResourceRequestHandlers();
|
| 489 |
+
this.sendResourceListChanged();
|
| 490 |
+
return registeredResourceTemplate;
|
| 491 |
+
}
|
| 492 |
+
}
|
| 493 |
+
_createRegisteredResource(name, title, uri, metadata, readCallback) {
|
| 494 |
+
const registeredResource = {
|
| 495 |
+
name,
|
| 496 |
+
title,
|
| 497 |
+
metadata,
|
| 498 |
+
readCallback,
|
| 499 |
+
enabled: true,
|
| 500 |
+
disable: () => registeredResource.update({ enabled: false }),
|
| 501 |
+
enable: () => registeredResource.update({ enabled: true }),
|
| 502 |
+
remove: () => registeredResource.update({ uri: null }),
|
| 503 |
+
update: updates => {
|
| 504 |
+
if (typeof updates.uri !== 'undefined' && updates.uri !== uri) {
|
| 505 |
+
delete this._registeredResources[uri];
|
| 506 |
+
if (updates.uri)
|
| 507 |
+
this._registeredResources[updates.uri] = registeredResource;
|
| 508 |
+
}
|
| 509 |
+
if (typeof updates.name !== 'undefined')
|
| 510 |
+
registeredResource.name = updates.name;
|
| 511 |
+
if (typeof updates.title !== 'undefined')
|
| 512 |
+
registeredResource.title = updates.title;
|
| 513 |
+
if (typeof updates.metadata !== 'undefined')
|
| 514 |
+
registeredResource.metadata = updates.metadata;
|
| 515 |
+
if (typeof updates.callback !== 'undefined')
|
| 516 |
+
registeredResource.readCallback = updates.callback;
|
| 517 |
+
if (typeof updates.enabled !== 'undefined')
|
| 518 |
+
registeredResource.enabled = updates.enabled;
|
| 519 |
+
this.sendResourceListChanged();
|
| 520 |
+
}
|
| 521 |
+
};
|
| 522 |
+
this._registeredResources[uri] = registeredResource;
|
| 523 |
+
return registeredResource;
|
| 524 |
+
}
|
| 525 |
+
_createRegisteredResourceTemplate(name, title, template, metadata, readCallback) {
|
| 526 |
+
const registeredResourceTemplate = {
|
| 527 |
+
resourceTemplate: template,
|
| 528 |
+
title,
|
| 529 |
+
metadata,
|
| 530 |
+
readCallback,
|
| 531 |
+
enabled: true,
|
| 532 |
+
disable: () => registeredResourceTemplate.update({ enabled: false }),
|
| 533 |
+
enable: () => registeredResourceTemplate.update({ enabled: true }),
|
| 534 |
+
remove: () => registeredResourceTemplate.update({ name: null }),
|
| 535 |
+
update: updates => {
|
| 536 |
+
if (typeof updates.name !== 'undefined' && updates.name !== name) {
|
| 537 |
+
delete this._registeredResourceTemplates[name];
|
| 538 |
+
if (updates.name)
|
| 539 |
+
this._registeredResourceTemplates[updates.name] = registeredResourceTemplate;
|
| 540 |
+
}
|
| 541 |
+
if (typeof updates.title !== 'undefined')
|
| 542 |
+
registeredResourceTemplate.title = updates.title;
|
| 543 |
+
if (typeof updates.template !== 'undefined')
|
| 544 |
+
registeredResourceTemplate.resourceTemplate = updates.template;
|
| 545 |
+
if (typeof updates.metadata !== 'undefined')
|
| 546 |
+
registeredResourceTemplate.metadata = updates.metadata;
|
| 547 |
+
if (typeof updates.callback !== 'undefined')
|
| 548 |
+
registeredResourceTemplate.readCallback = updates.callback;
|
| 549 |
+
if (typeof updates.enabled !== 'undefined')
|
| 550 |
+
registeredResourceTemplate.enabled = updates.enabled;
|
| 551 |
+
this.sendResourceListChanged();
|
| 552 |
+
}
|
| 553 |
+
};
|
| 554 |
+
this._registeredResourceTemplates[name] = registeredResourceTemplate;
|
| 555 |
+
// If the resource template has any completion callbacks, enable completions capability
|
| 556 |
+
const variableNames = template.uriTemplate.variableNames;
|
| 557 |
+
const hasCompleter = Array.isArray(variableNames) && variableNames.some(v => !!template.completeCallback(v));
|
| 558 |
+
if (hasCompleter) {
|
| 559 |
+
this.setCompletionRequestHandler();
|
| 560 |
+
}
|
| 561 |
+
return registeredResourceTemplate;
|
| 562 |
+
}
|
| 563 |
+
_createRegisteredPrompt(name, title, description, argsSchema, callback) {
|
| 564 |
+
const registeredPrompt = {
|
| 565 |
+
title,
|
| 566 |
+
description,
|
| 567 |
+
argsSchema: argsSchema === undefined ? undefined : objectFromShape(argsSchema),
|
| 568 |
+
callback,
|
| 569 |
+
enabled: true,
|
| 570 |
+
disable: () => registeredPrompt.update({ enabled: false }),
|
| 571 |
+
enable: () => registeredPrompt.update({ enabled: true }),
|
| 572 |
+
remove: () => registeredPrompt.update({ name: null }),
|
| 573 |
+
update: updates => {
|
| 574 |
+
if (typeof updates.name !== 'undefined' && updates.name !== name) {
|
| 575 |
+
delete this._registeredPrompts[name];
|
| 576 |
+
if (updates.name)
|
| 577 |
+
this._registeredPrompts[updates.name] = registeredPrompt;
|
| 578 |
+
}
|
| 579 |
+
if (typeof updates.title !== 'undefined')
|
| 580 |
+
registeredPrompt.title = updates.title;
|
| 581 |
+
if (typeof updates.description !== 'undefined')
|
| 582 |
+
registeredPrompt.description = updates.description;
|
| 583 |
+
if (typeof updates.argsSchema !== 'undefined')
|
| 584 |
+
registeredPrompt.argsSchema = objectFromShape(updates.argsSchema);
|
| 585 |
+
if (typeof updates.callback !== 'undefined')
|
| 586 |
+
registeredPrompt.callback = updates.callback;
|
| 587 |
+
if (typeof updates.enabled !== 'undefined')
|
| 588 |
+
registeredPrompt.enabled = updates.enabled;
|
| 589 |
+
this.sendPromptListChanged();
|
| 590 |
+
}
|
| 591 |
+
};
|
| 592 |
+
this._registeredPrompts[name] = registeredPrompt;
|
| 593 |
+
// If any argument uses a Completable schema, enable completions capability
|
| 594 |
+
if (argsSchema) {
|
| 595 |
+
const hasCompletable = Object.values(argsSchema).some(field => {
|
| 596 |
+
const inner = field instanceof ZodOptional ? field._def?.innerType : field;
|
| 597 |
+
return isCompletable(inner);
|
| 598 |
+
});
|
| 599 |
+
if (hasCompletable) {
|
| 600 |
+
this.setCompletionRequestHandler();
|
| 601 |
+
}
|
| 602 |
+
}
|
| 603 |
+
return registeredPrompt;
|
| 604 |
+
}
|
| 605 |
+
_createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, execution, _meta, handler) {
|
| 606 |
+
// Validate tool name according to SEP specification
|
| 607 |
+
validateAndWarnToolName(name);
|
| 608 |
+
const registeredTool = {
|
| 609 |
+
title,
|
| 610 |
+
description,
|
| 611 |
+
inputSchema: getZodSchemaObject(inputSchema),
|
| 612 |
+
outputSchema: getZodSchemaObject(outputSchema),
|
| 613 |
+
annotations,
|
| 614 |
+
execution,
|
| 615 |
+
_meta,
|
| 616 |
+
handler: handler,
|
| 617 |
+
enabled: true,
|
| 618 |
+
disable: () => registeredTool.update({ enabled: false }),
|
| 619 |
+
enable: () => registeredTool.update({ enabled: true }),
|
| 620 |
+
remove: () => registeredTool.update({ name: null }),
|
| 621 |
+
update: updates => {
|
| 622 |
+
if (typeof updates.name !== 'undefined' && updates.name !== name) {
|
| 623 |
+
if (typeof updates.name === 'string') {
|
| 624 |
+
validateAndWarnToolName(updates.name);
|
| 625 |
+
}
|
| 626 |
+
delete this._registeredTools[name];
|
| 627 |
+
if (updates.name)
|
| 628 |
+
this._registeredTools[updates.name] = registeredTool;
|
| 629 |
+
}
|
| 630 |
+
if (typeof updates.title !== 'undefined')
|
| 631 |
+
registeredTool.title = updates.title;
|
| 632 |
+
if (typeof updates.description !== 'undefined')
|
| 633 |
+
registeredTool.description = updates.description;
|
| 634 |
+
if (typeof updates.paramsSchema !== 'undefined')
|
| 635 |
+
registeredTool.inputSchema = objectFromShape(updates.paramsSchema);
|
| 636 |
+
if (typeof updates.outputSchema !== 'undefined')
|
| 637 |
+
registeredTool.outputSchema = objectFromShape(updates.outputSchema);
|
| 638 |
+
if (typeof updates.callback !== 'undefined')
|
| 639 |
+
registeredTool.handler = updates.callback;
|
| 640 |
+
if (typeof updates.annotations !== 'undefined')
|
| 641 |
+
registeredTool.annotations = updates.annotations;
|
| 642 |
+
if (typeof updates._meta !== 'undefined')
|
| 643 |
+
registeredTool._meta = updates._meta;
|
| 644 |
+
if (typeof updates.enabled !== 'undefined')
|
| 645 |
+
registeredTool.enabled = updates.enabled;
|
| 646 |
+
this.sendToolListChanged();
|
| 647 |
+
}
|
| 648 |
+
};
|
| 649 |
+
this._registeredTools[name] = registeredTool;
|
| 650 |
+
this.setToolRequestHandlers();
|
| 651 |
+
this.sendToolListChanged();
|
| 652 |
+
return registeredTool;
|
| 653 |
+
}
|
| 654 |
+
/**
|
| 655 |
+
* tool() implementation. Parses arguments passed to overrides defined above.
|
| 656 |
+
*/
|
| 657 |
+
tool(name, ...rest) {
|
| 658 |
+
if (this._registeredTools[name]) {
|
| 659 |
+
throw new Error(`Tool ${name} is already registered`);
|
| 660 |
+
}
|
| 661 |
+
let description;
|
| 662 |
+
let inputSchema;
|
| 663 |
+
let outputSchema;
|
| 664 |
+
let annotations;
|
| 665 |
+
// Tool properties are passed as separate arguments, with omissions allowed.
|
| 666 |
+
// Support for this style is frozen as of protocol version 2025-03-26. Future additions
|
| 667 |
+
// to tool definition should *NOT* be added.
|
| 668 |
+
if (typeof rest[0] === 'string') {
|
| 669 |
+
description = rest.shift();
|
| 670 |
+
}
|
| 671 |
+
// Handle the different overload combinations
|
| 672 |
+
if (rest.length > 1) {
|
| 673 |
+
// We have at least one more arg before the callback
|
| 674 |
+
const firstArg = rest[0];
|
| 675 |
+
if (isZodRawShapeCompat(firstArg)) {
|
| 676 |
+
// We have a params schema as the first arg
|
| 677 |
+
inputSchema = rest.shift();
|
| 678 |
+
// Check if the next arg is potentially annotations
|
| 679 |
+
if (rest.length > 1 && typeof rest[0] === 'object' && rest[0] !== null && !isZodRawShapeCompat(rest[0])) {
|
| 680 |
+
// Case: tool(name, paramsSchema, annotations, cb)
|
| 681 |
+
// Or: tool(name, description, paramsSchema, annotations, cb)
|
| 682 |
+
annotations = rest.shift();
|
| 683 |
+
}
|
| 684 |
+
}
|
| 685 |
+
else if (typeof firstArg === 'object' && firstArg !== null) {
|
| 686 |
+
// ToolAnnotations values are primitives. Nested objects indicate a misplaced schema
|
| 687 |
+
if (Object.values(firstArg).some(v => typeof v === 'object' && v !== null)) {
|
| 688 |
+
throw new Error(`Tool ${name} expected a Zod schema or ToolAnnotations, but received an unrecognized object`);
|
| 689 |
+
}
|
| 690 |
+
annotations = rest.shift();
|
| 691 |
+
}
|
| 692 |
+
}
|
| 693 |
+
const callback = rest[0];
|
| 694 |
+
return this._createRegisteredTool(name, undefined, description, inputSchema, outputSchema, annotations, { taskSupport: 'forbidden' }, undefined, callback);
|
| 695 |
+
}
|
| 696 |
+
/**
|
| 697 |
+
* Registers a tool with a config object and callback.
|
| 698 |
+
*/
|
| 699 |
+
registerTool(name, config, cb) {
|
| 700 |
+
if (this._registeredTools[name]) {
|
| 701 |
+
throw new Error(`Tool ${name} is already registered`);
|
| 702 |
+
}
|
| 703 |
+
const { title, description, inputSchema, outputSchema, annotations, _meta } = config;
|
| 704 |
+
return this._createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, { taskSupport: 'forbidden' }, _meta, cb);
|
| 705 |
+
}
|
| 706 |
+
prompt(name, ...rest) {
|
| 707 |
+
if (this._registeredPrompts[name]) {
|
| 708 |
+
throw new Error(`Prompt ${name} is already registered`);
|
| 709 |
+
}
|
| 710 |
+
let description;
|
| 711 |
+
if (typeof rest[0] === 'string') {
|
| 712 |
+
description = rest.shift();
|
| 713 |
+
}
|
| 714 |
+
let argsSchema;
|
| 715 |
+
if (rest.length > 1) {
|
| 716 |
+
argsSchema = rest.shift();
|
| 717 |
+
}
|
| 718 |
+
const cb = rest[0];
|
| 719 |
+
const registeredPrompt = this._createRegisteredPrompt(name, undefined, description, argsSchema, cb);
|
| 720 |
+
this.setPromptRequestHandlers();
|
| 721 |
+
this.sendPromptListChanged();
|
| 722 |
+
return registeredPrompt;
|
| 723 |
+
}
|
| 724 |
+
/**
|
| 725 |
+
* Registers a prompt with a config object and callback.
|
| 726 |
+
*/
|
| 727 |
+
registerPrompt(name, config, cb) {
|
| 728 |
+
if (this._registeredPrompts[name]) {
|
| 729 |
+
throw new Error(`Prompt ${name} is already registered`);
|
| 730 |
+
}
|
| 731 |
+
const { title, description, argsSchema } = config;
|
| 732 |
+
const registeredPrompt = this._createRegisteredPrompt(name, title, description, argsSchema, cb);
|
| 733 |
+
this.setPromptRequestHandlers();
|
| 734 |
+
this.sendPromptListChanged();
|
| 735 |
+
return registeredPrompt;
|
| 736 |
+
}
|
| 737 |
+
/**
|
| 738 |
+
* Checks if the server is connected to a transport.
|
| 739 |
+
* @returns True if the server is connected
|
| 740 |
+
*/
|
| 741 |
+
isConnected() {
|
| 742 |
+
return this.server.transport !== undefined;
|
| 743 |
+
}
|
| 744 |
+
/**
|
| 745 |
+
* Sends a logging message to the client, if connected.
|
| 746 |
+
* Note: You only need to send the parameters object, not the entire JSON RPC message
|
| 747 |
+
* @see LoggingMessageNotification
|
| 748 |
+
* @param params
|
| 749 |
+
* @param sessionId optional for stateless and backward compatibility
|
| 750 |
+
*/
|
| 751 |
+
async sendLoggingMessage(params, sessionId) {
|
| 752 |
+
return this.server.sendLoggingMessage(params, sessionId);
|
| 753 |
+
}
|
| 754 |
+
/**
|
| 755 |
+
* Sends a resource list changed event to the client, if connected.
|
| 756 |
+
*/
|
| 757 |
+
sendResourceListChanged() {
|
| 758 |
+
if (this.isConnected()) {
|
| 759 |
+
this.server.sendResourceListChanged();
|
| 760 |
+
}
|
| 761 |
+
}
|
| 762 |
+
/**
|
| 763 |
+
* Sends a tool list changed event to the client, if connected.
|
| 764 |
+
*/
|
| 765 |
+
sendToolListChanged() {
|
| 766 |
+
if (this.isConnected()) {
|
| 767 |
+
this.server.sendToolListChanged();
|
| 768 |
+
}
|
| 769 |
+
}
|
| 770 |
+
/**
|
| 771 |
+
* Sends a prompt list changed event to the client, if connected.
|
| 772 |
+
*/
|
| 773 |
+
sendPromptListChanged() {
|
| 774 |
+
if (this.isConnected()) {
|
| 775 |
+
this.server.sendPromptListChanged();
|
| 776 |
+
}
|
| 777 |
+
}
|
| 778 |
+
}
|
| 779 |
+
/**
|
| 780 |
+
* A resource template combines a URI pattern with optional functionality to enumerate
|
| 781 |
+
* all resources matching that pattern.
|
| 782 |
+
*/
|
| 783 |
+
export class ResourceTemplate {
|
| 784 |
+
constructor(uriTemplate, _callbacks) {
|
| 785 |
+
this._callbacks = _callbacks;
|
| 786 |
+
this._uriTemplate = typeof uriTemplate === 'string' ? new UriTemplate(uriTemplate) : uriTemplate;
|
| 787 |
+
}
|
| 788 |
+
/**
|
| 789 |
+
* Gets the URI template pattern.
|
| 790 |
+
*/
|
| 791 |
+
get uriTemplate() {
|
| 792 |
+
return this._uriTemplate;
|
| 793 |
+
}
|
| 794 |
+
/**
|
| 795 |
+
* Gets the list callback, if one was provided.
|
| 796 |
+
*/
|
| 797 |
+
get listCallback() {
|
| 798 |
+
return this._callbacks.list;
|
| 799 |
+
}
|
| 800 |
+
/**
|
| 801 |
+
* Gets the callback for completing a specific URI template variable, if one was provided.
|
| 802 |
+
*/
|
| 803 |
+
completeCallback(variable) {
|
| 804 |
+
return this._callbacks.complete?.[variable];
|
| 805 |
+
}
|
| 806 |
+
}
|
| 807 |
+
const EMPTY_OBJECT_JSON_SCHEMA = {
|
| 808 |
+
type: 'object',
|
| 809 |
+
properties: {}
|
| 810 |
+
};
|
| 811 |
+
/**
|
| 812 |
+
* Checks if a value looks like a Zod schema by checking for parse/safeParse methods.
|
| 813 |
+
*/
|
| 814 |
+
function isZodTypeLike(value) {
|
| 815 |
+
return (value !== null &&
|
| 816 |
+
typeof value === 'object' &&
|
| 817 |
+
'parse' in value &&
|
| 818 |
+
typeof value.parse === 'function' &&
|
| 819 |
+
'safeParse' in value &&
|
| 820 |
+
typeof value.safeParse === 'function');
|
| 821 |
+
}
|
| 822 |
+
/**
|
| 823 |
+
* Checks if an object is a Zod schema instance (v3 or v4).
|
| 824 |
+
*
|
| 825 |
+
* Zod schemas have internal markers:
|
| 826 |
+
* - v3: `_def` property
|
| 827 |
+
* - v4: `_zod` property
|
| 828 |
+
*
|
| 829 |
+
* This includes transformed schemas like z.preprocess(), z.transform(), z.pipe().
|
| 830 |
+
*/
|
| 831 |
+
function isZodSchemaInstance(obj) {
|
| 832 |
+
return '_def' in obj || '_zod' in obj || isZodTypeLike(obj);
|
| 833 |
+
}
|
| 834 |
+
/**
|
| 835 |
+
* Checks if an object is a "raw shape" - a plain object where values are Zod schemas.
|
| 836 |
+
*
|
| 837 |
+
* Raw shapes are used as shorthand: `{ name: z.string() }` instead of `z.object({ name: z.string() })`.
|
| 838 |
+
*
|
| 839 |
+
* IMPORTANT: This must NOT match actual Zod schema instances (like z.preprocess, z.pipe),
|
| 840 |
+
* which have internal properties that could be mistaken for schema values.
|
| 841 |
+
*/
|
| 842 |
+
function isZodRawShapeCompat(obj) {
|
| 843 |
+
if (typeof obj !== 'object' || obj === null) {
|
| 844 |
+
return false;
|
| 845 |
+
}
|
| 846 |
+
// If it's already a Zod schema instance, it's NOT a raw shape
|
| 847 |
+
if (isZodSchemaInstance(obj)) {
|
| 848 |
+
return false;
|
| 849 |
+
}
|
| 850 |
+
// Empty objects are valid raw shapes (tools with no parameters)
|
| 851 |
+
if (Object.keys(obj).length === 0) {
|
| 852 |
+
return true;
|
| 853 |
+
}
|
| 854 |
+
// A raw shape has at least one property that is a Zod schema
|
| 855 |
+
return Object.values(obj).some(isZodTypeLike);
|
| 856 |
+
}
|
| 857 |
+
/**
|
| 858 |
+
* Converts a provided Zod schema to a Zod object if it is a ZodRawShapeCompat,
|
| 859 |
+
* otherwise returns the schema as is. Throws if the value is not a valid Zod schema.
|
| 860 |
+
*/
|
| 861 |
+
function getZodSchemaObject(schema) {
|
| 862 |
+
if (!schema) {
|
| 863 |
+
return undefined;
|
| 864 |
+
}
|
| 865 |
+
if (isZodRawShapeCompat(schema)) {
|
| 866 |
+
return objectFromShape(schema);
|
| 867 |
+
}
|
| 868 |
+
if (!isZodSchemaInstance(schema)) {
|
| 869 |
+
throw new Error('inputSchema must be a Zod schema or raw shape, received an unrecognized object');
|
| 870 |
+
}
|
| 871 |
+
return schema;
|
| 872 |
+
}
|
| 873 |
+
function promptArgumentsFromSchema(schema) {
|
| 874 |
+
const shape = getObjectShape(schema);
|
| 875 |
+
if (!shape)
|
| 876 |
+
return [];
|
| 877 |
+
return Object.entries(shape).map(([name, field]) => {
|
| 878 |
+
// Get description - works for both v3 and v4
|
| 879 |
+
const description = getSchemaDescription(field);
|
| 880 |
+
// Check if optional - works for both v3 and v4
|
| 881 |
+
const isOptional = isSchemaOptional(field);
|
| 882 |
+
return {
|
| 883 |
+
name,
|
| 884 |
+
description,
|
| 885 |
+
required: !isOptional
|
| 886 |
+
};
|
| 887 |
+
});
|
| 888 |
+
}
|
| 889 |
+
function getMethodValue(schema) {
|
| 890 |
+
const shape = getObjectShape(schema);
|
| 891 |
+
const methodSchema = shape?.method;
|
| 892 |
+
if (!methodSchema) {
|
| 893 |
+
throw new Error('Schema is missing a method literal');
|
| 894 |
+
}
|
| 895 |
+
// Extract literal value - works for both v3 and v4
|
| 896 |
+
const value = getLiteralValue(methodSchema);
|
| 897 |
+
if (typeof value === 'string') {
|
| 898 |
+
return value;
|
| 899 |
+
}
|
| 900 |
+
throw new Error('Schema method literal must be a string');
|
| 901 |
+
}
|
| 902 |
+
function createCompletionResult(suggestions) {
|
| 903 |
+
return {
|
| 904 |
+
completion: {
|
| 905 |
+
values: suggestions.slice(0, 100),
|
| 906 |
+
total: suggestions.length,
|
| 907 |
+
hasMore: suggestions.length > 100
|
| 908 |
+
}
|
| 909 |
+
};
|
| 910 |
+
}
|
| 911 |
+
const EMPTY_COMPLETION_RESULT = {
|
| 912 |
+
completion: {
|
| 913 |
+
values: [],
|
| 914 |
+
hasMore: false
|
| 915 |
+
}
|
| 916 |
+
};
|
| 917 |
+
//# sourceMappingURL=mcp.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../../src/server/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AACnD,OAAO,EAMH,qBAAqB,EACrB,cAAc,EACd,cA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|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/middleware/hostHeaderValidation.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { RequestHandler } from 'express';
|
| 2 |
+
/**
|
| 3 |
+
* Express middleware for DNS rebinding protection.
|
| 4 |
+
* Validates Host header hostname (port-agnostic) against an allowed list.
|
| 5 |
+
*
|
| 6 |
+
* This is particularly important for servers without authorization or HTTPS,
|
| 7 |
+
* such as localhost servers or development servers. DNS rebinding attacks can
|
| 8 |
+
* bypass same-origin policy by manipulating DNS to point a domain to a
|
| 9 |
+
* localhost address, allowing malicious websites to access your local server.
|
| 10 |
+
*
|
| 11 |
+
* @param allowedHostnames - List of allowed hostnames (without ports).
|
| 12 |
+
* For IPv6, provide the address with brackets (e.g., '[::1]').
|
| 13 |
+
* @returns Express middleware function
|
| 14 |
+
*
|
| 15 |
+
* @example
|
| 16 |
+
* ```typescript
|
| 17 |
+
* const middleware = hostHeaderValidation(['localhost', '127.0.0.1', '[::1]']);
|
| 18 |
+
* app.use(middleware);
|
| 19 |
+
* ```
|
| 20 |
+
*/
|
| 21 |
+
export declare function hostHeaderValidation(allowedHostnames: string[]): RequestHandler;
|
| 22 |
+
/**
|
| 23 |
+
* Convenience middleware for localhost DNS rebinding protection.
|
| 24 |
+
* Allows only localhost, 127.0.0.1, and [::1] (IPv6 localhost) hostnames.
|
| 25 |
+
*
|
| 26 |
+
* @example
|
| 27 |
+
* ```typescript
|
| 28 |
+
* app.use(localhostHostValidation());
|
| 29 |
+
* ```
|
| 30 |
+
*/
|
| 31 |
+
export declare function localhostHostValidation(): RequestHandler;
|
| 32 |
+
//# sourceMappingURL=hostHeaderValidation.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/middleware/hostHeaderValidation.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"hostHeaderValidation.d.ts","sourceRoot":"","sources":["../../../../src/server/middleware/hostHeaderValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,cAAc,EAAE,MAAM,SAAS,CAAC;AAE1E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,EAAE,GAAG,cAAc,CA4C/E;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,IAAI,cAAc,CAExD"}
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/middleware/hostHeaderValidation.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Express middleware for DNS rebinding protection.
|
| 3 |
+
* Validates Host header hostname (port-agnostic) against an allowed list.
|
| 4 |
+
*
|
| 5 |
+
* This is particularly important for servers without authorization or HTTPS,
|
| 6 |
+
* such as localhost servers or development servers. DNS rebinding attacks can
|
| 7 |
+
* bypass same-origin policy by manipulating DNS to point a domain to a
|
| 8 |
+
* localhost address, allowing malicious websites to access your local server.
|
| 9 |
+
*
|
| 10 |
+
* @param allowedHostnames - List of allowed hostnames (without ports).
|
| 11 |
+
* For IPv6, provide the address with brackets (e.g., '[::1]').
|
| 12 |
+
* @returns Express middleware function
|
| 13 |
+
*
|
| 14 |
+
* @example
|
| 15 |
+
* ```typescript
|
| 16 |
+
* const middleware = hostHeaderValidation(['localhost', '127.0.0.1', '[::1]']);
|
| 17 |
+
* app.use(middleware);
|
| 18 |
+
* ```
|
| 19 |
+
*/
|
| 20 |
+
export function hostHeaderValidation(allowedHostnames) {
|
| 21 |
+
return (req, res, next) => {
|
| 22 |
+
const hostHeader = req.headers.host;
|
| 23 |
+
if (!hostHeader) {
|
| 24 |
+
res.status(403).json({
|
| 25 |
+
jsonrpc: '2.0',
|
| 26 |
+
error: {
|
| 27 |
+
code: -32000,
|
| 28 |
+
message: 'Missing Host header'
|
| 29 |
+
},
|
| 30 |
+
id: null
|
| 31 |
+
});
|
| 32 |
+
return;
|
| 33 |
+
}
|
| 34 |
+
// Use URL API to parse hostname (handles IPv4, IPv6, and regular hostnames)
|
| 35 |
+
let hostname;
|
| 36 |
+
try {
|
| 37 |
+
hostname = new URL(`http://${hostHeader}`).hostname;
|
| 38 |
+
}
|
| 39 |
+
catch {
|
| 40 |
+
res.status(403).json({
|
| 41 |
+
jsonrpc: '2.0',
|
| 42 |
+
error: {
|
| 43 |
+
code: -32000,
|
| 44 |
+
message: `Invalid Host header: ${hostHeader}`
|
| 45 |
+
},
|
| 46 |
+
id: null
|
| 47 |
+
});
|
| 48 |
+
return;
|
| 49 |
+
}
|
| 50 |
+
if (!allowedHostnames.includes(hostname)) {
|
| 51 |
+
res.status(403).json({
|
| 52 |
+
jsonrpc: '2.0',
|
| 53 |
+
error: {
|
| 54 |
+
code: -32000,
|
| 55 |
+
message: `Invalid Host: ${hostname}`
|
| 56 |
+
},
|
| 57 |
+
id: null
|
| 58 |
+
});
|
| 59 |
+
return;
|
| 60 |
+
}
|
| 61 |
+
next();
|
| 62 |
+
};
|
| 63 |
+
}
|
| 64 |
+
/**
|
| 65 |
+
* Convenience middleware for localhost DNS rebinding protection.
|
| 66 |
+
* Allows only localhost, 127.0.0.1, and [::1] (IPv6 localhost) hostnames.
|
| 67 |
+
*
|
| 68 |
+
* @example
|
| 69 |
+
* ```typescript
|
| 70 |
+
* app.use(localhostHostValidation());
|
| 71 |
+
* ```
|
| 72 |
+
*/
|
| 73 |
+
export function localhostHostValidation() {
|
| 74 |
+
return hostHeaderValidation(['localhost', '127.0.0.1', '[::1]']);
|
| 75 |
+
}
|
| 76 |
+
//# sourceMappingURL=hostHeaderValidation.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/middleware/hostHeaderValidation.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"hostHeaderValidation.js","sourceRoot":"","sources":["../../../../src/server/middleware/hostHeaderValidation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,oBAAoB,CAAC,gBAA0B;IAC3D,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QACvD,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;QACpC,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACjB,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE;oBACH,IAAI,EAAE,CAAC,KAAK;oBACZ,OAAO,EAAE,qBAAqB;iBACjC;gBACD,EAAE,EAAE,IAAI;aACX,CAAC,CAAC;YACH,OAAO;QACX,CAAC;QAED,4EAA4E;QAC5E,IAAI,QAAgB,CAAC;QACrB,IA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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
| 2 |
+
import { Transport } from '../shared/transport.js';
|
| 3 |
+
import { JSONRPCMessage, MessageExtraInfo } from '../types.js';
|
| 4 |
+
import { AuthInfo } from './auth/types.js';
|
| 5 |
+
/**
|
| 6 |
+
* Configuration options for SSEServerTransport.
|
| 7 |
+
*/
|
| 8 |
+
export interface SSEServerTransportOptions {
|
| 9 |
+
/**
|
| 10 |
+
* List of allowed host header values for DNS rebinding protection.
|
| 11 |
+
* If not specified, host validation is disabled.
|
| 12 |
+
* @deprecated Use the `hostHeaderValidation` middleware from `@modelcontextprotocol/sdk/server/middleware/hostHeaderValidation.js` instead,
|
| 13 |
+
* or use `createMcpExpressApp` from `@modelcontextprotocol/sdk/server/express.js` which includes localhost protection by default.
|
| 14 |
+
*/
|
| 15 |
+
allowedHosts?: string[];
|
| 16 |
+
/**
|
| 17 |
+
* List of allowed origin header values for DNS rebinding protection.
|
| 18 |
+
* If not specified, origin validation is disabled.
|
| 19 |
+
* @deprecated Use the `hostHeaderValidation` middleware from `@modelcontextprotocol/sdk/server/middleware/hostHeaderValidation.js` instead,
|
| 20 |
+
* or use `createMcpExpressApp` from `@modelcontextprotocol/sdk/server/express.js` which includes localhost protection by default.
|
| 21 |
+
*/
|
| 22 |
+
allowedOrigins?: string[];
|
| 23 |
+
/**
|
| 24 |
+
* Enable DNS rebinding protection (requires allowedHosts and/or allowedOrigins to be configured).
|
| 25 |
+
* Default is false for backwards compatibility.
|
| 26 |
+
* @deprecated Use the `hostHeaderValidation` middleware from `@modelcontextprotocol/sdk/server/middleware/hostHeaderValidation.js` instead,
|
| 27 |
+
* or use `createMcpExpressApp` from `@modelcontextprotocol/sdk/server/express.js` which includes localhost protection by default.
|
| 28 |
+
*/
|
| 29 |
+
enableDnsRebindingProtection?: boolean;
|
| 30 |
+
}
|
| 31 |
+
/**
|
| 32 |
+
* Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests.
|
| 33 |
+
*
|
| 34 |
+
* This transport is only available in Node.js environments.
|
| 35 |
+
* @deprecated SSEServerTransport is deprecated. Use StreamableHTTPServerTransport instead.
|
| 36 |
+
*/
|
| 37 |
+
export declare class SSEServerTransport implements Transport {
|
| 38 |
+
private _endpoint;
|
| 39 |
+
private res;
|
| 40 |
+
private _sseResponse?;
|
| 41 |
+
private _sessionId;
|
| 42 |
+
private _options;
|
| 43 |
+
onclose?: () => void;
|
| 44 |
+
onerror?: (error: Error) => void;
|
| 45 |
+
onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
|
| 46 |
+
/**
|
| 47 |
+
* Creates a new SSE server transport, which will direct the client to POST messages to the relative or absolute URL identified by `_endpoint`.
|
| 48 |
+
*/
|
| 49 |
+
constructor(_endpoint: string, res: ServerResponse, options?: SSEServerTransportOptions);
|
| 50 |
+
/**
|
| 51 |
+
* Validates request headers for DNS rebinding protection.
|
| 52 |
+
* @returns Error message if validation fails, undefined if validation passes.
|
| 53 |
+
*/
|
| 54 |
+
private validateRequestHeaders;
|
| 55 |
+
/**
|
| 56 |
+
* Handles the initial SSE connection request.
|
| 57 |
+
*
|
| 58 |
+
* This should be called when a GET request is made to establish the SSE stream.
|
| 59 |
+
*/
|
| 60 |
+
start(): Promise<void>;
|
| 61 |
+
/**
|
| 62 |
+
* Handles incoming POST messages.
|
| 63 |
+
*
|
| 64 |
+
* This should be called when a POST request is made to send a message to the server.
|
| 65 |
+
*/
|
| 66 |
+
handlePostMessage(req: IncomingMessage & {
|
| 67 |
+
auth?: AuthInfo;
|
| 68 |
+
}, res: ServerResponse, parsedBody?: unknown): Promise<void>;
|
| 69 |
+
/**
|
| 70 |
+
* Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.
|
| 71 |
+
*/
|
| 72 |
+
handleMessage(message: unknown, extra?: MessageExtraInfo): Promise<void>;
|
| 73 |
+
close(): Promise<void>;
|
| 74 |
+
send(message: JSONRPCMessage): Promise<void>;
|
| 75 |
+
/**
|
| 76 |
+
* Returns the session ID for this transport.
|
| 77 |
+
*
|
| 78 |
+
* This can be used to route incoming POST requests.
|
| 79 |
+
*/
|
| 80 |
+
get sessionId(): string;
|
| 81 |
+
}
|
| 82 |
+
//# sourceMappingURL=sse.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../../src/server/sse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAwB,gBAAgB,EAAe,MAAM,aAAa,CAAC;AAGlG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAK3C;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B;;;;;OAKG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;CAC1C;AAED;;;;;GAKG;AACH,qBAAa,kBAAmB,YAAW,SAAS;IAY5C,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,GAAG;IAZf,OAAO,CAAC,YAAY,CAAC,CAAiB;IACtC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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { randomUUID } from 'node:crypto';
|
| 2 |
+
import { TLSSocket } from 'node:tls';
|
| 3 |
+
import { JSONRPCMessageSchema } from '../types.js';
|
| 4 |
+
import getRawBody from 'raw-body';
|
| 5 |
+
import contentType from 'content-type';
|
| 6 |
+
import { URL } from 'node:url';
|
| 7 |
+
const MAXIMUM_MESSAGE_SIZE = '4mb';
|
| 8 |
+
/**
|
| 9 |
+
* Server transport for SSE: this will send messages over an SSE connection and receive messages from HTTP POST requests.
|
| 10 |
+
*
|
| 11 |
+
* This transport is only available in Node.js environments.
|
| 12 |
+
* @deprecated SSEServerTransport is deprecated. Use StreamableHTTPServerTransport instead.
|
| 13 |
+
*/
|
| 14 |
+
export class SSEServerTransport {
|
| 15 |
+
/**
|
| 16 |
+
* Creates a new SSE server transport, which will direct the client to POST messages to the relative or absolute URL identified by `_endpoint`.
|
| 17 |
+
*/
|
| 18 |
+
constructor(_endpoint, res, options) {
|
| 19 |
+
this._endpoint = _endpoint;
|
| 20 |
+
this.res = res;
|
| 21 |
+
this._sessionId = randomUUID();
|
| 22 |
+
this._options = options || { enableDnsRebindingProtection: false };
|
| 23 |
+
}
|
| 24 |
+
/**
|
| 25 |
+
* Validates request headers for DNS rebinding protection.
|
| 26 |
+
* @returns Error message if validation fails, undefined if validation passes.
|
| 27 |
+
*/
|
| 28 |
+
validateRequestHeaders(req) {
|
| 29 |
+
// Skip validation if protection is not enabled
|
| 30 |
+
if (!this._options.enableDnsRebindingProtection) {
|
| 31 |
+
return undefined;
|
| 32 |
+
}
|
| 33 |
+
// Validate Host header if allowedHosts is configured
|
| 34 |
+
if (this._options.allowedHosts && this._options.allowedHosts.length > 0) {
|
| 35 |
+
const hostHeader = req.headers.host;
|
| 36 |
+
if (!hostHeader || !this._options.allowedHosts.includes(hostHeader)) {
|
| 37 |
+
return `Invalid Host header: ${hostHeader}`;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
// Validate Origin header if allowedOrigins is configured
|
| 41 |
+
if (this._options.allowedOrigins && this._options.allowedOrigins.length > 0) {
|
| 42 |
+
const originHeader = req.headers.origin;
|
| 43 |
+
if (originHeader && !this._options.allowedOrigins.includes(originHeader)) {
|
| 44 |
+
return `Invalid Origin header: ${originHeader}`;
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
return undefined;
|
| 48 |
+
}
|
| 49 |
+
/**
|
| 50 |
+
* Handles the initial SSE connection request.
|
| 51 |
+
*
|
| 52 |
+
* This should be called when a GET request is made to establish the SSE stream.
|
| 53 |
+
*/
|
| 54 |
+
async start() {
|
| 55 |
+
if (this._sseResponse) {
|
| 56 |
+
throw new Error('SSEServerTransport already started! If using Server class, note that connect() calls start() automatically.');
|
| 57 |
+
}
|
| 58 |
+
this.res.writeHead(200, {
|
| 59 |
+
'Content-Type': 'text/event-stream',
|
| 60 |
+
'Cache-Control': 'no-cache, no-transform',
|
| 61 |
+
Connection: 'keep-alive'
|
| 62 |
+
});
|
| 63 |
+
// Send the endpoint event
|
| 64 |
+
// Use a dummy base URL because this._endpoint is relative.
|
| 65 |
+
// This allows using URL/URLSearchParams for robust parameter handling.
|
| 66 |
+
const dummyBase = 'http://localhost'; // Any valid base works
|
| 67 |
+
const endpointUrl = new URL(this._endpoint, dummyBase);
|
| 68 |
+
endpointUrl.searchParams.set('sessionId', this._sessionId);
|
| 69 |
+
// Reconstruct the relative URL string (pathname + search + hash)
|
| 70 |
+
const relativeUrlWithSession = endpointUrl.pathname + endpointUrl.search + endpointUrl.hash;
|
| 71 |
+
this.res.write(`event: endpoint\ndata: ${relativeUrlWithSession}\n\n`);
|
| 72 |
+
this._sseResponse = this.res;
|
| 73 |
+
this.res.on('close', () => {
|
| 74 |
+
this._sseResponse = undefined;
|
| 75 |
+
this.onclose?.();
|
| 76 |
+
});
|
| 77 |
+
}
|
| 78 |
+
/**
|
| 79 |
+
* Handles incoming POST messages.
|
| 80 |
+
*
|
| 81 |
+
* This should be called when a POST request is made to send a message to the server.
|
| 82 |
+
*/
|
| 83 |
+
async handlePostMessage(req, res, parsedBody) {
|
| 84 |
+
if (!this._sseResponse) {
|
| 85 |
+
const message = 'SSE connection not established';
|
| 86 |
+
res.writeHead(500).end(message);
|
| 87 |
+
throw new Error(message);
|
| 88 |
+
}
|
| 89 |
+
// Validate request headers for DNS rebinding protection
|
| 90 |
+
const validationError = this.validateRequestHeaders(req);
|
| 91 |
+
if (validationError) {
|
| 92 |
+
res.writeHead(403).end(validationError);
|
| 93 |
+
this.onerror?.(new Error(validationError));
|
| 94 |
+
return;
|
| 95 |
+
}
|
| 96 |
+
const authInfo = req.auth;
|
| 97 |
+
const host = req.headers.host;
|
| 98 |
+
const protocol = req.socket instanceof TLSSocket ? 'https' : 'http';
|
| 99 |
+
const fullUrl = host && req.url ? new URL(req.url, `${protocol}://${host}`) : undefined;
|
| 100 |
+
const requestInfo = {
|
| 101 |
+
headers: req.headers,
|
| 102 |
+
url: fullUrl
|
| 103 |
+
};
|
| 104 |
+
let body;
|
| 105 |
+
try {
|
| 106 |
+
const ct = contentType.parse(req.headers['content-type'] ?? '');
|
| 107 |
+
if (ct.type !== 'application/json') {
|
| 108 |
+
throw new Error(`Unsupported content-type: ${ct.type}`);
|
| 109 |
+
}
|
| 110 |
+
body =
|
| 111 |
+
parsedBody ??
|
| 112 |
+
(await getRawBody(req, {
|
| 113 |
+
limit: MAXIMUM_MESSAGE_SIZE,
|
| 114 |
+
encoding: ct.parameters.charset ?? 'utf-8'
|
| 115 |
+
}));
|
| 116 |
+
}
|
| 117 |
+
catch (error) {
|
| 118 |
+
res.writeHead(400).end(String(error));
|
| 119 |
+
this.onerror?.(error);
|
| 120 |
+
return;
|
| 121 |
+
}
|
| 122 |
+
try {
|
| 123 |
+
await this.handleMessage(typeof body === 'string' ? JSON.parse(body) : body, { requestInfo, authInfo });
|
| 124 |
+
}
|
| 125 |
+
catch {
|
| 126 |
+
res.writeHead(400).end(`Invalid message: ${body}`);
|
| 127 |
+
return;
|
| 128 |
+
}
|
| 129 |
+
res.writeHead(202).end('Accepted');
|
| 130 |
+
}
|
| 131 |
+
/**
|
| 132 |
+
* Handle a client message, regardless of how it arrived. This can be used to inform the server of messages that arrive via a means different than HTTP POST.
|
| 133 |
+
*/
|
| 134 |
+
async handleMessage(message, extra) {
|
| 135 |
+
let parsedMessage;
|
| 136 |
+
try {
|
| 137 |
+
parsedMessage = JSONRPCMessageSchema.parse(message);
|
| 138 |
+
}
|
| 139 |
+
catch (error) {
|
| 140 |
+
this.onerror?.(error);
|
| 141 |
+
throw error;
|
| 142 |
+
}
|
| 143 |
+
this.onmessage?.(parsedMessage, extra);
|
| 144 |
+
}
|
| 145 |
+
async close() {
|
| 146 |
+
this._sseResponse?.end();
|
| 147 |
+
this._sseResponse = undefined;
|
| 148 |
+
this.onclose?.();
|
| 149 |
+
}
|
| 150 |
+
async send(message) {
|
| 151 |
+
if (!this._sseResponse) {
|
| 152 |
+
throw new Error('Not connected');
|
| 153 |
+
}
|
| 154 |
+
this._sseResponse.write(`event: message\ndata: ${JSON.stringify(message)}\n\n`);
|
| 155 |
+
}
|
| 156 |
+
/**
|
| 157 |
+
* Returns the session ID for this transport.
|
| 158 |
+
*
|
| 159 |
+
* This can be used to route incoming POST requests.
|
| 160 |
+
*/
|
| 161 |
+
get sessionId() {
|
| 162 |
+
return this._sessionId;
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
//# sourceMappingURL=sse.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../../src/server/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAkB,oBAAoB,EAAiC,MAAM,aAAa,CAAC;AAClG,OAAO,UAAU,MAAM,UAAU,CAAC;AAClC,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,oBAAoB,GAAG,KAAK,CAAC;AA+BnC;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IAQ3B;;OAEG;IACH,YACY,SAAiB,EACjB,GAAmB,EAC3B,OAAmC;QAF3B,cAAS,GAAT,SAAS,CAAQ;QACjB,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Y,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACrC,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACpF,CAAC;IAED;;;;OAIG;IACH,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ"}
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Readable, Writable } from 'node:stream';
|
| 2 |
+
import { JSONRPCMessage } from '../types.js';
|
| 3 |
+
import { Transport } from '../shared/transport.js';
|
| 4 |
+
/**
|
| 5 |
+
* Server transport for stdio: this communicates with an MCP client by reading from the current process' stdin and writing to stdout.
|
| 6 |
+
*
|
| 7 |
+
* This transport is only available in Node.js environments.
|
| 8 |
+
*/
|
| 9 |
+
export declare class StdioServerTransport implements Transport {
|
| 10 |
+
private _stdin;
|
| 11 |
+
private _stdout;
|
| 12 |
+
private _readBuffer;
|
| 13 |
+
private _started;
|
| 14 |
+
constructor(_stdin?: Readable, _stdout?: Writable);
|
| 15 |
+
onclose?: () => void;
|
| 16 |
+
onerror?: (error: Error) => void;
|
| 17 |
+
onmessage?: (message: JSONRPCMessage) => void;
|
| 18 |
+
_ondata: (chunk: Buffer) => void;
|
| 19 |
+
_onerror: (error: Error) => void;
|
| 20 |
+
/**
|
| 21 |
+
* Starts listening for messages on stdin.
|
| 22 |
+
*/
|
| 23 |
+
start(): Promise<void>;
|
| 24 |
+
private processReadBuffer;
|
| 25 |
+
close(): Promise<void>;
|
| 26 |
+
send(message: JSONRPCMessage): Promise<void>;
|
| 27 |
+
}
|
| 28 |
+
//# sourceMappingURL=stdio.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../../src/server/stdio.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD;;;;GAIG;AACH,qBAAa,oBAAqB,YAAW,SAAS;IAK9C,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,OAAO;IALnB,OAAO,CAAC,WAAW,CAAgC;IACnD,OAAO,CAAC,QAAQ,CAAS;gBAGb,MAAM,GAAE,QAAwB,EAChC,OAAO,GAAE,QAAyB;IAG9C,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IAG9C,OAAO,UAAW,MAAM,UAGtB;IACF,QAAQ,UAAW,KAAK,UAEtB;IAEF;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY5B,OAAO,CAAC,iBAAiB;IAenB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB5B,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAU/C"}
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import process from 'node:process';
|
| 2 |
+
import { ReadBuffer, serializeMessage } from '../shared/stdio.js';
|
| 3 |
+
/**
|
| 4 |
+
* Server transport for stdio: this communicates with an MCP client by reading from the current process' stdin and writing to stdout.
|
| 5 |
+
*
|
| 6 |
+
* This transport is only available in Node.js environments.
|
| 7 |
+
*/
|
| 8 |
+
export class StdioServerTransport {
|
| 9 |
+
constructor(_stdin = process.stdin, _stdout = process.stdout) {
|
| 10 |
+
this._stdin = _stdin;
|
| 11 |
+
this._stdout = _stdout;
|
| 12 |
+
this._readBuffer = new ReadBuffer();
|
| 13 |
+
this._started = false;
|
| 14 |
+
// Arrow functions to bind `this` properly, while maintaining function identity.
|
| 15 |
+
this._ondata = (chunk) => {
|
| 16 |
+
this._readBuffer.append(chunk);
|
| 17 |
+
this.processReadBuffer();
|
| 18 |
+
};
|
| 19 |
+
this._onerror = (error) => {
|
| 20 |
+
this.onerror?.(error);
|
| 21 |
+
};
|
| 22 |
+
}
|
| 23 |
+
/**
|
| 24 |
+
* Starts listening for messages on stdin.
|
| 25 |
+
*/
|
| 26 |
+
async start() {
|
| 27 |
+
if (this._started) {
|
| 28 |
+
throw new Error('StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.');
|
| 29 |
+
}
|
| 30 |
+
this._started = true;
|
| 31 |
+
this._stdin.on('data', this._ondata);
|
| 32 |
+
this._stdin.on('error', this._onerror);
|
| 33 |
+
}
|
| 34 |
+
processReadBuffer() {
|
| 35 |
+
while (true) {
|
| 36 |
+
try {
|
| 37 |
+
const message = this._readBuffer.readMessage();
|
| 38 |
+
if (message === null) {
|
| 39 |
+
break;
|
| 40 |
+
}
|
| 41 |
+
this.onmessage?.(message);
|
| 42 |
+
}
|
| 43 |
+
catch (error) {
|
| 44 |
+
this.onerror?.(error);
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
async close() {
|
| 49 |
+
// Remove our event listeners first
|
| 50 |
+
this._stdin.off('data', this._ondata);
|
| 51 |
+
this._stdin.off('error', this._onerror);
|
| 52 |
+
// Check if we were the only data listener
|
| 53 |
+
const remainingDataListeners = this._stdin.listenerCount('data');
|
| 54 |
+
if (remainingDataListeners === 0) {
|
| 55 |
+
// Only pause stdin if we were the only listener
|
| 56 |
+
// This prevents interfering with other parts of the application that might be using stdin
|
| 57 |
+
this._stdin.pause();
|
| 58 |
+
}
|
| 59 |
+
// Clear the buffer and notify closure
|
| 60 |
+
this._readBuffer.clear();
|
| 61 |
+
this.onclose?.();
|
| 62 |
+
}
|
| 63 |
+
send(message) {
|
| 64 |
+
return new Promise(resolve => {
|
| 65 |
+
const json = serializeMessage(message);
|
| 66 |
+
if (this._stdout.write(json)) {
|
| 67 |
+
resolve();
|
| 68 |
+
}
|
| 69 |
+
else {
|
| 70 |
+
this._stdout.once('drain', resolve);
|
| 71 |
+
}
|
| 72 |
+
});
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
//# sourceMappingURL=stdio.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"stdio.js","sourceRoot":"","sources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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Node.js HTTP Streamable HTTP Server Transport
|
| 3 |
+
*
|
| 4 |
+
* This is a thin wrapper around `WebStandardStreamableHTTPServerTransport` that provides
|
| 5 |
+
* compatibility with Node.js HTTP server (IncomingMessage/ServerResponse).
|
| 6 |
+
*
|
| 7 |
+
* For web-standard environments (Cloudflare Workers, Deno, Bun), use `WebStandardStreamableHTTPServerTransport` directly.
|
| 8 |
+
*/
|
| 9 |
+
import { IncomingMessage, ServerResponse } from 'node:http';
|
| 10 |
+
import { Transport } from '../shared/transport.js';
|
| 11 |
+
import { AuthInfo } from './auth/types.js';
|
| 12 |
+
import { MessageExtraInfo, JSONRPCMessage, RequestId } from '../types.js';
|
| 13 |
+
import { WebStandardStreamableHTTPServerTransportOptions, EventStore, StreamId, EventId } from './webStandardStreamableHttp.js';
|
| 14 |
+
export type { EventStore, StreamId, EventId };
|
| 15 |
+
/**
|
| 16 |
+
* Configuration options for StreamableHTTPServerTransport
|
| 17 |
+
*
|
| 18 |
+
* This is an alias for WebStandardStreamableHTTPServerTransportOptions for backward compatibility.
|
| 19 |
+
*/
|
| 20 |
+
export type StreamableHTTPServerTransportOptions = WebStandardStreamableHTTPServerTransportOptions;
|
| 21 |
+
/**
|
| 22 |
+
* Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification.
|
| 23 |
+
* It supports both SSE streaming and direct HTTP responses.
|
| 24 |
+
*
|
| 25 |
+
* This is a wrapper around `WebStandardStreamableHTTPServerTransport` that provides Node.js HTTP compatibility.
|
| 26 |
+
* It uses the `@hono/node-server` library to convert between Node.js HTTP and Web Standard APIs.
|
| 27 |
+
*
|
| 28 |
+
* Usage example:
|
| 29 |
+
*
|
| 30 |
+
* ```typescript
|
| 31 |
+
* // Stateful mode - server sets the session ID
|
| 32 |
+
* const statefulTransport = new StreamableHTTPServerTransport({
|
| 33 |
+
* sessionIdGenerator: () => randomUUID(),
|
| 34 |
+
* });
|
| 35 |
+
*
|
| 36 |
+
* // Stateless mode - explicitly set session ID to undefined
|
| 37 |
+
* const statelessTransport = new StreamableHTTPServerTransport({
|
| 38 |
+
* sessionIdGenerator: undefined,
|
| 39 |
+
* });
|
| 40 |
+
*
|
| 41 |
+
* // Using with pre-parsed request body
|
| 42 |
+
* app.post('/mcp', (req, res) => {
|
| 43 |
+
* transport.handleRequest(req, res, req.body);
|
| 44 |
+
* });
|
| 45 |
+
* ```
|
| 46 |
+
*
|
| 47 |
+
* In stateful mode:
|
| 48 |
+
* - Session ID is generated and included in response headers
|
| 49 |
+
* - Session ID is always included in initialization responses
|
| 50 |
+
* - Requests with invalid session IDs are rejected with 404 Not Found
|
| 51 |
+
* - Non-initialization requests without a session ID are rejected with 400 Bad Request
|
| 52 |
+
* - State is maintained in-memory (connections, message history)
|
| 53 |
+
*
|
| 54 |
+
* In stateless mode:
|
| 55 |
+
* - No Session ID is included in any responses
|
| 56 |
+
* - No session validation is performed
|
| 57 |
+
*/
|
| 58 |
+
export declare class StreamableHTTPServerTransport implements Transport {
|
| 59 |
+
private _webStandardTransport;
|
| 60 |
+
private _requestListener;
|
| 61 |
+
private _requestContext;
|
| 62 |
+
constructor(options?: StreamableHTTPServerTransportOptions);
|
| 63 |
+
/**
|
| 64 |
+
* Gets the session ID for this transport instance.
|
| 65 |
+
*/
|
| 66 |
+
get sessionId(): string | undefined;
|
| 67 |
+
/**
|
| 68 |
+
* Sets callback for when the transport is closed.
|
| 69 |
+
*/
|
| 70 |
+
set onclose(handler: (() => void) | undefined);
|
| 71 |
+
get onclose(): (() => void) | undefined;
|
| 72 |
+
/**
|
| 73 |
+
* Sets callback for transport errors.
|
| 74 |
+
*/
|
| 75 |
+
set onerror(handler: ((error: Error) => void) | undefined);
|
| 76 |
+
get onerror(): ((error: Error) => void) | undefined;
|
| 77 |
+
/**
|
| 78 |
+
* Sets callback for incoming messages.
|
| 79 |
+
*/
|
| 80 |
+
set onmessage(handler: ((message: JSONRPCMessage, extra?: MessageExtraInfo) => void) | undefined);
|
| 81 |
+
get onmessage(): ((message: JSONRPCMessage, extra?: MessageExtraInfo) => void) | undefined;
|
| 82 |
+
/**
|
| 83 |
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
| 84 |
+
* for the Streamable HTTP transport as connections are managed per-request.
|
| 85 |
+
*/
|
| 86 |
+
start(): Promise<void>;
|
| 87 |
+
/**
|
| 88 |
+
* Closes the transport and all active connections.
|
| 89 |
+
*/
|
| 90 |
+
close(): Promise<void>;
|
| 91 |
+
/**
|
| 92 |
+
* Sends a JSON-RPC message through the transport.
|
| 93 |
+
*/
|
| 94 |
+
send(message: JSONRPCMessage, options?: {
|
| 95 |
+
relatedRequestId?: RequestId;
|
| 96 |
+
}): Promise<void>;
|
| 97 |
+
/**
|
| 98 |
+
* Handles an incoming HTTP request, whether GET or POST.
|
| 99 |
+
*
|
| 100 |
+
* This method converts Node.js HTTP objects to Web Standard Request/Response
|
| 101 |
+
* and delegates to the underlying WebStandardStreamableHTTPServerTransport.
|
| 102 |
+
*
|
| 103 |
+
* @param req - Node.js IncomingMessage, optionally with auth property from middleware
|
| 104 |
+
* @param res - Node.js ServerResponse
|
| 105 |
+
* @param parsedBody - Optional pre-parsed body from body-parser middleware
|
| 106 |
+
*/
|
| 107 |
+
handleRequest(req: IncomingMessage & {
|
| 108 |
+
auth?: AuthInfo;
|
| 109 |
+
}, res: ServerResponse, parsedBody?: unknown): Promise<void>;
|
| 110 |
+
/**
|
| 111 |
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
| 112 |
+
* Use this to implement polling behavior during long-running operations -
|
| 113 |
+
* client will reconnect after the retry interval specified in the priming event.
|
| 114 |
+
*/
|
| 115 |
+
closeSSEStream(requestId: RequestId): void;
|
| 116 |
+
/**
|
| 117 |
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
| 118 |
+
* Use this to implement polling behavior for server-initiated notifications.
|
| 119 |
+
*/
|
| 120 |
+
closeStandaloneSSEStream(): void;
|
| 121 |
+
}
|
| 122 |
+
//# sourceMappingURL=streamableHttp.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"streamableHttp.d.ts","sourceRoot":"","sources":["../../../src/server/streamableHttp.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,QAAQ,EA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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Node.js HTTP Streamable HTTP Server Transport
|
| 3 |
+
*
|
| 4 |
+
* This is a thin wrapper around `WebStandardStreamableHTTPServerTransport` that provides
|
| 5 |
+
* compatibility with Node.js HTTP server (IncomingMessage/ServerResponse).
|
| 6 |
+
*
|
| 7 |
+
* For web-standard environments (Cloudflare Workers, Deno, Bun), use `WebStandardStreamableHTTPServerTransport` directly.
|
| 8 |
+
*/
|
| 9 |
+
import { getRequestListener } from '@hono/node-server';
|
| 10 |
+
import { WebStandardStreamableHTTPServerTransport } from './webStandardStreamableHttp.js';
|
| 11 |
+
/**
|
| 12 |
+
* Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification.
|
| 13 |
+
* It supports both SSE streaming and direct HTTP responses.
|
| 14 |
+
*
|
| 15 |
+
* This is a wrapper around `WebStandardStreamableHTTPServerTransport` that provides Node.js HTTP compatibility.
|
| 16 |
+
* It uses the `@hono/node-server` library to convert between Node.js HTTP and Web Standard APIs.
|
| 17 |
+
*
|
| 18 |
+
* Usage example:
|
| 19 |
+
*
|
| 20 |
+
* ```typescript
|
| 21 |
+
* // Stateful mode - server sets the session ID
|
| 22 |
+
* const statefulTransport = new StreamableHTTPServerTransport({
|
| 23 |
+
* sessionIdGenerator: () => randomUUID(),
|
| 24 |
+
* });
|
| 25 |
+
*
|
| 26 |
+
* // Stateless mode - explicitly set session ID to undefined
|
| 27 |
+
* const statelessTransport = new StreamableHTTPServerTransport({
|
| 28 |
+
* sessionIdGenerator: undefined,
|
| 29 |
+
* });
|
| 30 |
+
*
|
| 31 |
+
* // Using with pre-parsed request body
|
| 32 |
+
* app.post('/mcp', (req, res) => {
|
| 33 |
+
* transport.handleRequest(req, res, req.body);
|
| 34 |
+
* });
|
| 35 |
+
* ```
|
| 36 |
+
*
|
| 37 |
+
* In stateful mode:
|
| 38 |
+
* - Session ID is generated and included in response headers
|
| 39 |
+
* - Session ID is always included in initialization responses
|
| 40 |
+
* - Requests with invalid session IDs are rejected with 404 Not Found
|
| 41 |
+
* - Non-initialization requests without a session ID are rejected with 400 Bad Request
|
| 42 |
+
* - State is maintained in-memory (connections, message history)
|
| 43 |
+
*
|
| 44 |
+
* In stateless mode:
|
| 45 |
+
* - No Session ID is included in any responses
|
| 46 |
+
* - No session validation is performed
|
| 47 |
+
*/
|
| 48 |
+
export class StreamableHTTPServerTransport {
|
| 49 |
+
constructor(options = {}) {
|
| 50 |
+
// Store auth and parsedBody per request for passing through to handleRequest
|
| 51 |
+
this._requestContext = new WeakMap();
|
| 52 |
+
this._webStandardTransport = new WebStandardStreamableHTTPServerTransport(options);
|
| 53 |
+
// Create a request listener that wraps the web standard transport
|
| 54 |
+
// getRequestListener converts Node.js HTTP to Web Standard and properly handles SSE streaming
|
| 55 |
+
// overrideGlobalObjects: false prevents Hono from overwriting global Response, which would
|
| 56 |
+
// break frameworks like Next.js whose response classes extend the native Response
|
| 57 |
+
this._requestListener = getRequestListener(async (webRequest) => {
|
| 58 |
+
// Get context if available (set during handleRequest)
|
| 59 |
+
const context = this._requestContext.get(webRequest);
|
| 60 |
+
return this._webStandardTransport.handleRequest(webRequest, {
|
| 61 |
+
authInfo: context?.authInfo,
|
| 62 |
+
parsedBody: context?.parsedBody
|
| 63 |
+
});
|
| 64 |
+
}, { overrideGlobalObjects: false });
|
| 65 |
+
}
|
| 66 |
+
/**
|
| 67 |
+
* Gets the session ID for this transport instance.
|
| 68 |
+
*/
|
| 69 |
+
get sessionId() {
|
| 70 |
+
return this._webStandardTransport.sessionId;
|
| 71 |
+
}
|
| 72 |
+
/**
|
| 73 |
+
* Sets callback for when the transport is closed.
|
| 74 |
+
*/
|
| 75 |
+
set onclose(handler) {
|
| 76 |
+
this._webStandardTransport.onclose = handler;
|
| 77 |
+
}
|
| 78 |
+
get onclose() {
|
| 79 |
+
return this._webStandardTransport.onclose;
|
| 80 |
+
}
|
| 81 |
+
/**
|
| 82 |
+
* Sets callback for transport errors.
|
| 83 |
+
*/
|
| 84 |
+
set onerror(handler) {
|
| 85 |
+
this._webStandardTransport.onerror = handler;
|
| 86 |
+
}
|
| 87 |
+
get onerror() {
|
| 88 |
+
return this._webStandardTransport.onerror;
|
| 89 |
+
}
|
| 90 |
+
/**
|
| 91 |
+
* Sets callback for incoming messages.
|
| 92 |
+
*/
|
| 93 |
+
set onmessage(handler) {
|
| 94 |
+
this._webStandardTransport.onmessage = handler;
|
| 95 |
+
}
|
| 96 |
+
get onmessage() {
|
| 97 |
+
return this._webStandardTransport.onmessage;
|
| 98 |
+
}
|
| 99 |
+
/**
|
| 100 |
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
| 101 |
+
* for the Streamable HTTP transport as connections are managed per-request.
|
| 102 |
+
*/
|
| 103 |
+
async start() {
|
| 104 |
+
return this._webStandardTransport.start();
|
| 105 |
+
}
|
| 106 |
+
/**
|
| 107 |
+
* Closes the transport and all active connections.
|
| 108 |
+
*/
|
| 109 |
+
async close() {
|
| 110 |
+
return this._webStandardTransport.close();
|
| 111 |
+
}
|
| 112 |
+
/**
|
| 113 |
+
* Sends a JSON-RPC message through the transport.
|
| 114 |
+
*/
|
| 115 |
+
async send(message, options) {
|
| 116 |
+
return this._webStandardTransport.send(message, options);
|
| 117 |
+
}
|
| 118 |
+
/**
|
| 119 |
+
* Handles an incoming HTTP request, whether GET or POST.
|
| 120 |
+
*
|
| 121 |
+
* This method converts Node.js HTTP objects to Web Standard Request/Response
|
| 122 |
+
* and delegates to the underlying WebStandardStreamableHTTPServerTransport.
|
| 123 |
+
*
|
| 124 |
+
* @param req - Node.js IncomingMessage, optionally with auth property from middleware
|
| 125 |
+
* @param res - Node.js ServerResponse
|
| 126 |
+
* @param parsedBody - Optional pre-parsed body from body-parser middleware
|
| 127 |
+
*/
|
| 128 |
+
async handleRequest(req, res, parsedBody) {
|
| 129 |
+
// Store context for this request to pass through auth and parsedBody
|
| 130 |
+
// We need to intercept the request creation to attach this context
|
| 131 |
+
const authInfo = req.auth;
|
| 132 |
+
// Create a custom handler that includes our context
|
| 133 |
+
// overrideGlobalObjects: false prevents Hono from overwriting global Response, which would
|
| 134 |
+
// break frameworks like Next.js whose response classes extend the native Response
|
| 135 |
+
const handler = getRequestListener(async (webRequest) => {
|
| 136 |
+
return this._webStandardTransport.handleRequest(webRequest, {
|
| 137 |
+
authInfo,
|
| 138 |
+
parsedBody
|
| 139 |
+
});
|
| 140 |
+
}, { overrideGlobalObjects: false });
|
| 141 |
+
// Delegate to the request listener which handles all the Node.js <-> Web Standard conversion
|
| 142 |
+
// including proper SSE streaming support
|
| 143 |
+
await handler(req, res);
|
| 144 |
+
}
|
| 145 |
+
/**
|
| 146 |
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
| 147 |
+
* Use this to implement polling behavior during long-running operations -
|
| 148 |
+
* client will reconnect after the retry interval specified in the priming event.
|
| 149 |
+
*/
|
| 150 |
+
closeSSEStream(requestId) {
|
| 151 |
+
this._webStandardTransport.closeSSEStream(requestId);
|
| 152 |
+
}
|
| 153 |
+
/**
|
| 154 |
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
| 155 |
+
* Use this to implement polling behavior for server-initiated notifications.
|
| 156 |
+
*/
|
| 157 |
+
closeStandaloneSSEStream() {
|
| 158 |
+
this._webStandardTransport.closeStandaloneSSEStream();
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
//# sourceMappingURL=streamableHttp.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/streamableHttp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"streamableHttp.js","sourceRoot":"","sources":["../../../src/server/streamableHttp.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAIvD,OAAO,EACH,wCAAwC,EAK3C,MAAM,gCAAgC,CAAC;AAYxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,OAAO,6BAA6B;IAMtC,YAAY,UAAgD,EAAE;QAH9D,6EAA6E;QACrE,oBAAe,GAAoE,IAAI,OAAO,EAAE,CAAC;QAGrG,IAAI,CAAC,qBAAqB,GAAG,IAAI,wCAAwC,CAAC,OAAO,CAAC,CAAC;QAEnF,kEAAkE;QAClE,8FAA8F;QAC9F,2FAA2F;QAC3F,kFAAkF;QAClF,IAAI,CAAC,gBAAgB,GAAG,kBAAkB,CACtC,KAAK,EAAE,UAAmB,EAAE,EAAE;YAC1B,sDAAsD;YACtD,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACrD,OAAO,IAAI,CAAC,qBAAqB,CAAC,aAAa,CAAC,UAAU,EAAE;gBACxD,QAAQ,EAAE,OAAO,EAAE,QAAQ;gBAC3B,UAAU,EAAE,OAAO,EAAE,UAAU;aAClC,CAAC,CAAC;QACP,CAAC,EACD,EAAE,qBAAqB,EAAE,KAAK,EAAE,CACnC,CAAC;IACN,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACT,OAA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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Web Standards Streamable HTTP Server Transport
|
| 3 |
+
*
|
| 4 |
+
* This is the core transport implementation using Web Standard APIs (Request, Response, ReadableStream).
|
| 5 |
+
* It can run on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.
|
| 6 |
+
*
|
| 7 |
+
* For Node.js Express/HTTP compatibility, use `StreamableHTTPServerTransport` which wraps this transport.
|
| 8 |
+
*/
|
| 9 |
+
import { Transport } from '../shared/transport.js';
|
| 10 |
+
import { AuthInfo } from './auth/types.js';
|
| 11 |
+
import { MessageExtraInfo, JSONRPCMessage, RequestId } from '../types.js';
|
| 12 |
+
export type StreamId = string;
|
| 13 |
+
export type EventId = string;
|
| 14 |
+
/**
|
| 15 |
+
* Interface for resumability support via event storage
|
| 16 |
+
*/
|
| 17 |
+
export interface EventStore {
|
| 18 |
+
/**
|
| 19 |
+
* Stores an event for later retrieval
|
| 20 |
+
* @param streamId ID of the stream the event belongs to
|
| 21 |
+
* @param message The JSON-RPC message to store
|
| 22 |
+
* @returns The generated event ID for the stored event
|
| 23 |
+
*/
|
| 24 |
+
storeEvent(streamId: StreamId, message: JSONRPCMessage): Promise<EventId>;
|
| 25 |
+
/**
|
| 26 |
+
* Get the stream ID associated with a given event ID.
|
| 27 |
+
* @param eventId The event ID to look up
|
| 28 |
+
* @returns The stream ID, or undefined if not found
|
| 29 |
+
*
|
| 30 |
+
* Optional: If not provided, the SDK will use the streamId returned by
|
| 31 |
+
* replayEventsAfter for stream mapping.
|
| 32 |
+
*/
|
| 33 |
+
getStreamIdForEventId?(eventId: EventId): Promise<StreamId | undefined>;
|
| 34 |
+
replayEventsAfter(lastEventId: EventId, { send }: {
|
| 35 |
+
send: (eventId: EventId, message: JSONRPCMessage) => Promise<void>;
|
| 36 |
+
}): Promise<StreamId>;
|
| 37 |
+
}
|
| 38 |
+
/**
|
| 39 |
+
* Configuration options for WebStandardStreamableHTTPServerTransport
|
| 40 |
+
*/
|
| 41 |
+
export interface WebStandardStreamableHTTPServerTransportOptions {
|
| 42 |
+
/**
|
| 43 |
+
* Function that generates a session ID for the transport.
|
| 44 |
+
* The session ID SHOULD be globally unique and cryptographically secure (e.g., a securely generated UUID, a JWT, or a cryptographic hash)
|
| 45 |
+
*
|
| 46 |
+
* If not provided, session management is disabled (stateless mode).
|
| 47 |
+
*/
|
| 48 |
+
sessionIdGenerator?: () => string;
|
| 49 |
+
/**
|
| 50 |
+
* A callback for session initialization events
|
| 51 |
+
* This is called when the server initializes a new session.
|
| 52 |
+
* Useful in cases when you need to register multiple mcp sessions
|
| 53 |
+
* and need to keep track of them.
|
| 54 |
+
* @param sessionId The generated session ID
|
| 55 |
+
*/
|
| 56 |
+
onsessioninitialized?: (sessionId: string) => void | Promise<void>;
|
| 57 |
+
/**
|
| 58 |
+
* A callback for session close events
|
| 59 |
+
* This is called when the server closes a session due to a DELETE request.
|
| 60 |
+
* Useful in cases when you need to clean up resources associated with the session.
|
| 61 |
+
* Note that this is different from the transport closing, if you are handling
|
| 62 |
+
* HTTP requests from multiple nodes you might want to close each
|
| 63 |
+
* WebStandardStreamableHTTPServerTransport after a request is completed while still keeping the
|
| 64 |
+
* session open/running.
|
| 65 |
+
* @param sessionId The session ID that was closed
|
| 66 |
+
*/
|
| 67 |
+
onsessionclosed?: (sessionId: string) => void | Promise<void>;
|
| 68 |
+
/**
|
| 69 |
+
* If true, the server will return JSON responses instead of starting an SSE stream.
|
| 70 |
+
* This can be useful for simple request/response scenarios without streaming.
|
| 71 |
+
* Default is false (SSE streams are preferred).
|
| 72 |
+
*/
|
| 73 |
+
enableJsonResponse?: boolean;
|
| 74 |
+
/**
|
| 75 |
+
* Event store for resumability support
|
| 76 |
+
* If provided, resumability will be enabled, allowing clients to reconnect and resume messages
|
| 77 |
+
*/
|
| 78 |
+
eventStore?: EventStore;
|
| 79 |
+
/**
|
| 80 |
+
* List of allowed host header values for DNS rebinding protection.
|
| 81 |
+
* If not specified, host validation is disabled.
|
| 82 |
+
* @deprecated Use external middleware for host validation instead.
|
| 83 |
+
*/
|
| 84 |
+
allowedHosts?: string[];
|
| 85 |
+
/**
|
| 86 |
+
* List of allowed origin header values for DNS rebinding protection.
|
| 87 |
+
* If not specified, origin validation is disabled.
|
| 88 |
+
* @deprecated Use external middleware for origin validation instead.
|
| 89 |
+
*/
|
| 90 |
+
allowedOrigins?: string[];
|
| 91 |
+
/**
|
| 92 |
+
* Enable DNS rebinding protection (requires allowedHosts and/or allowedOrigins to be configured).
|
| 93 |
+
* Default is false for backwards compatibility.
|
| 94 |
+
* @deprecated Use external middleware for DNS rebinding protection instead.
|
| 95 |
+
*/
|
| 96 |
+
enableDnsRebindingProtection?: boolean;
|
| 97 |
+
/**
|
| 98 |
+
* Retry interval in milliseconds to suggest to clients in SSE retry field.
|
| 99 |
+
* When set, the server will send a retry field in SSE priming events to control
|
| 100 |
+
* client reconnection timing for polling behavior.
|
| 101 |
+
*/
|
| 102 |
+
retryInterval?: number;
|
| 103 |
+
}
|
| 104 |
+
/**
|
| 105 |
+
* Options for handling a request
|
| 106 |
+
*/
|
| 107 |
+
export interface HandleRequestOptions {
|
| 108 |
+
/**
|
| 109 |
+
* Pre-parsed request body. If provided, the transport will use this instead of parsing req.json().
|
| 110 |
+
* Useful when using body-parser middleware that has already parsed the body.
|
| 111 |
+
*/
|
| 112 |
+
parsedBody?: unknown;
|
| 113 |
+
/**
|
| 114 |
+
* Authentication info from middleware. If provided, will be passed to message handlers.
|
| 115 |
+
*/
|
| 116 |
+
authInfo?: AuthInfo;
|
| 117 |
+
}
|
| 118 |
+
/**
|
| 119 |
+
* Server transport for Web Standards Streamable HTTP: this implements the MCP Streamable HTTP transport specification
|
| 120 |
+
* using Web Standard APIs (Request, Response, ReadableStream).
|
| 121 |
+
*
|
| 122 |
+
* This transport works on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.
|
| 123 |
+
*
|
| 124 |
+
* Usage example:
|
| 125 |
+
*
|
| 126 |
+
* ```typescript
|
| 127 |
+
* // Stateful mode - server sets the session ID
|
| 128 |
+
* const statefulTransport = new WebStandardStreamableHTTPServerTransport({
|
| 129 |
+
* sessionIdGenerator: () => crypto.randomUUID(),
|
| 130 |
+
* });
|
| 131 |
+
*
|
| 132 |
+
* // Stateless mode - explicitly set session ID to undefined
|
| 133 |
+
* const statelessTransport = new WebStandardStreamableHTTPServerTransport({
|
| 134 |
+
* sessionIdGenerator: undefined,
|
| 135 |
+
* });
|
| 136 |
+
*
|
| 137 |
+
* // Hono.js usage
|
| 138 |
+
* app.all('/mcp', async (c) => {
|
| 139 |
+
* return transport.handleRequest(c.req.raw);
|
| 140 |
+
* });
|
| 141 |
+
*
|
| 142 |
+
* // Cloudflare Workers usage
|
| 143 |
+
* export default {
|
| 144 |
+
* async fetch(request: Request): Promise<Response> {
|
| 145 |
+
* return transport.handleRequest(request);
|
| 146 |
+
* }
|
| 147 |
+
* };
|
| 148 |
+
* ```
|
| 149 |
+
*
|
| 150 |
+
* In stateful mode:
|
| 151 |
+
* - Session ID is generated and included in response headers
|
| 152 |
+
* - Session ID is always included in initialization responses
|
| 153 |
+
* - Requests with invalid session IDs are rejected with 404 Not Found
|
| 154 |
+
* - Non-initialization requests without a session ID are rejected with 400 Bad Request
|
| 155 |
+
* - State is maintained in-memory (connections, message history)
|
| 156 |
+
*
|
| 157 |
+
* In stateless mode:
|
| 158 |
+
* - No Session ID is included in any responses
|
| 159 |
+
* - No session validation is performed
|
| 160 |
+
*/
|
| 161 |
+
export declare class WebStandardStreamableHTTPServerTransport implements Transport {
|
| 162 |
+
private sessionIdGenerator;
|
| 163 |
+
private _started;
|
| 164 |
+
private _hasHandledRequest;
|
| 165 |
+
private _streamMapping;
|
| 166 |
+
private _requestToStreamMapping;
|
| 167 |
+
private _requestResponseMap;
|
| 168 |
+
private _initialized;
|
| 169 |
+
private _enableJsonResponse;
|
| 170 |
+
private _standaloneSseStreamId;
|
| 171 |
+
private _eventStore?;
|
| 172 |
+
private _onsessioninitialized?;
|
| 173 |
+
private _onsessionclosed?;
|
| 174 |
+
private _allowedHosts?;
|
| 175 |
+
private _allowedOrigins?;
|
| 176 |
+
private _enableDnsRebindingProtection;
|
| 177 |
+
private _retryInterval?;
|
| 178 |
+
sessionId?: string;
|
| 179 |
+
onclose?: () => void;
|
| 180 |
+
onerror?: (error: Error) => void;
|
| 181 |
+
onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;
|
| 182 |
+
constructor(options?: WebStandardStreamableHTTPServerTransportOptions);
|
| 183 |
+
/**
|
| 184 |
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
| 185 |
+
* for the Streamable HTTP transport as connections are managed per-request.
|
| 186 |
+
*/
|
| 187 |
+
start(): Promise<void>;
|
| 188 |
+
/**
|
| 189 |
+
* Helper to create a JSON error response
|
| 190 |
+
*/
|
| 191 |
+
private createJsonErrorResponse;
|
| 192 |
+
/**
|
| 193 |
+
* Validates request headers for DNS rebinding protection.
|
| 194 |
+
* @returns Error response if validation fails, undefined if validation passes.
|
| 195 |
+
*/
|
| 196 |
+
private validateRequestHeaders;
|
| 197 |
+
/**
|
| 198 |
+
* Handles an incoming HTTP request, whether GET, POST, or DELETE
|
| 199 |
+
* Returns a Response object (Web Standard)
|
| 200 |
+
*/
|
| 201 |
+
handleRequest(req: Request, options?: HandleRequestOptions): Promise<Response>;
|
| 202 |
+
/**
|
| 203 |
+
* Writes a priming event to establish resumption capability.
|
| 204 |
+
* Only sends if eventStore is configured (opt-in for resumability) and
|
| 205 |
+
* the client's protocol version supports empty SSE data (>= 2025-11-25).
|
| 206 |
+
*/
|
| 207 |
+
private writePrimingEvent;
|
| 208 |
+
/**
|
| 209 |
+
* Handles GET requests for SSE stream
|
| 210 |
+
*/
|
| 211 |
+
private handleGetRequest;
|
| 212 |
+
/**
|
| 213 |
+
* Replays events that would have been sent after the specified event ID
|
| 214 |
+
* Only used when resumability is enabled
|
| 215 |
+
*/
|
| 216 |
+
private replayEvents;
|
| 217 |
+
/**
|
| 218 |
+
* Writes an event to an SSE stream via controller with proper formatting
|
| 219 |
+
*/
|
| 220 |
+
private writeSSEEvent;
|
| 221 |
+
/**
|
| 222 |
+
* Handles unsupported requests (PUT, PATCH, etc.)
|
| 223 |
+
*/
|
| 224 |
+
private handleUnsupportedRequest;
|
| 225 |
+
/**
|
| 226 |
+
* Handles POST requests containing JSON-RPC messages
|
| 227 |
+
*/
|
| 228 |
+
private handlePostRequest;
|
| 229 |
+
/**
|
| 230 |
+
* Handles DELETE requests to terminate sessions
|
| 231 |
+
*/
|
| 232 |
+
private handleDeleteRequest;
|
| 233 |
+
/**
|
| 234 |
+
* Validates session ID for non-initialization requests.
|
| 235 |
+
* Returns Response error if invalid, undefined otherwise
|
| 236 |
+
*/
|
| 237 |
+
private validateSession;
|
| 238 |
+
/**
|
| 239 |
+
* Validates the MCP-Protocol-Version header on incoming requests.
|
| 240 |
+
*
|
| 241 |
+
* For initialization: Version negotiation handles unknown versions gracefully
|
| 242 |
+
* (server responds with its supported version).
|
| 243 |
+
*
|
| 244 |
+
* For subsequent requests with MCP-Protocol-Version header:
|
| 245 |
+
* - Accept if in supported list
|
| 246 |
+
* - 400 if unsupported
|
| 247 |
+
*
|
| 248 |
+
* For HTTP requests without the MCP-Protocol-Version header:
|
| 249 |
+
* - Accept and default to the version negotiated at initialization
|
| 250 |
+
*/
|
| 251 |
+
private validateProtocolVersion;
|
| 252 |
+
close(): Promise<void>;
|
| 253 |
+
/**
|
| 254 |
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
| 255 |
+
* Use this to implement polling behavior during long-running operations -
|
| 256 |
+
* client will reconnect after the retry interval specified in the priming event.
|
| 257 |
+
*/
|
| 258 |
+
closeSSEStream(requestId: RequestId): void;
|
| 259 |
+
/**
|
| 260 |
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
| 261 |
+
* Use this to implement polling behavior for server-initiated notifications.
|
| 262 |
+
*/
|
| 263 |
+
closeStandaloneSSEStream(): void;
|
| 264 |
+
send(message: JSONRPCMessage, options?: {
|
| 265 |
+
relatedRequestId?: RequestId;
|
| 266 |
+
}): Promise<void>;
|
| 267 |
+
}
|
| 268 |
+
//# sourceMappingURL=webStandardStreamableHttp.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"webStandardStreamableHttp.d.ts","sourceRoot":"","sources":["../../../src/server/webStandardStreamableHttp.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACH,gBAAgB,EAMhB,cAAc,EAEd,SAAS,EAGZ,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC9B,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB;;;;;OAKG;IACH,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1E;;;;;;;OAOG;IACH,qBAAqB,CAAC,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;IAExE,iBAAiB,CACb,WAAW,EAAE,OAAO,EACpB,EACI,IAAI,EACP,EAAE;QACC,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KACtE,GACF,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxB;AAgBD;;GAEG;AACH,MAAM,WAAW,+CAA+C;IAC5D;;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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Web Standards Streamable HTTP Server Transport
|
| 3 |
+
*
|
| 4 |
+
* This is the core transport implementation using Web Standard APIs (Request, Response, ReadableStream).
|
| 5 |
+
* It can run on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.
|
| 6 |
+
*
|
| 7 |
+
* For Node.js Express/HTTP compatibility, use `StreamableHTTPServerTransport` which wraps this transport.
|
| 8 |
+
*/
|
| 9 |
+
import { isInitializeRequest, isJSONRPCErrorResponse, isJSONRPCRequest, isJSONRPCResultResponse, JSONRPCMessageSchema, SUPPORTED_PROTOCOL_VERSIONS, DEFAULT_NEGOTIATED_PROTOCOL_VERSION } from '../types.js';
|
| 10 |
+
/**
|
| 11 |
+
* Server transport for Web Standards Streamable HTTP: this implements the MCP Streamable HTTP transport specification
|
| 12 |
+
* using Web Standard APIs (Request, Response, ReadableStream).
|
| 13 |
+
*
|
| 14 |
+
* This transport works on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.
|
| 15 |
+
*
|
| 16 |
+
* Usage example:
|
| 17 |
+
*
|
| 18 |
+
* ```typescript
|
| 19 |
+
* // Stateful mode - server sets the session ID
|
| 20 |
+
* const statefulTransport = new WebStandardStreamableHTTPServerTransport({
|
| 21 |
+
* sessionIdGenerator: () => crypto.randomUUID(),
|
| 22 |
+
* });
|
| 23 |
+
*
|
| 24 |
+
* // Stateless mode - explicitly set session ID to undefined
|
| 25 |
+
* const statelessTransport = new WebStandardStreamableHTTPServerTransport({
|
| 26 |
+
* sessionIdGenerator: undefined,
|
| 27 |
+
* });
|
| 28 |
+
*
|
| 29 |
+
* // Hono.js usage
|
| 30 |
+
* app.all('/mcp', async (c) => {
|
| 31 |
+
* return transport.handleRequest(c.req.raw);
|
| 32 |
+
* });
|
| 33 |
+
*
|
| 34 |
+
* // Cloudflare Workers usage
|
| 35 |
+
* export default {
|
| 36 |
+
* async fetch(request: Request): Promise<Response> {
|
| 37 |
+
* return transport.handleRequest(request);
|
| 38 |
+
* }
|
| 39 |
+
* };
|
| 40 |
+
* ```
|
| 41 |
+
*
|
| 42 |
+
* In stateful mode:
|
| 43 |
+
* - Session ID is generated and included in response headers
|
| 44 |
+
* - Session ID is always included in initialization responses
|
| 45 |
+
* - Requests with invalid session IDs are rejected with 404 Not Found
|
| 46 |
+
* - Non-initialization requests without a session ID are rejected with 400 Bad Request
|
| 47 |
+
* - State is maintained in-memory (connections, message history)
|
| 48 |
+
*
|
| 49 |
+
* In stateless mode:
|
| 50 |
+
* - No Session ID is included in any responses
|
| 51 |
+
* - No session validation is performed
|
| 52 |
+
*/
|
| 53 |
+
export class WebStandardStreamableHTTPServerTransport {
|
| 54 |
+
constructor(options = {}) {
|
| 55 |
+
this._started = false;
|
| 56 |
+
this._hasHandledRequest = false;
|
| 57 |
+
this._streamMapping = new Map();
|
| 58 |
+
this._requestToStreamMapping = new Map();
|
| 59 |
+
this._requestResponseMap = new Map();
|
| 60 |
+
this._initialized = false;
|
| 61 |
+
this._enableJsonResponse = false;
|
| 62 |
+
this._standaloneSseStreamId = '_GET_stream';
|
| 63 |
+
this.sessionIdGenerator = options.sessionIdGenerator;
|
| 64 |
+
this._enableJsonResponse = options.enableJsonResponse ?? false;
|
| 65 |
+
this._eventStore = options.eventStore;
|
| 66 |
+
this._onsessioninitialized = options.onsessioninitialized;
|
| 67 |
+
this._onsessionclosed = options.onsessionclosed;
|
| 68 |
+
this._allowedHosts = options.allowedHosts;
|
| 69 |
+
this._allowedOrigins = options.allowedOrigins;
|
| 70 |
+
this._enableDnsRebindingProtection = options.enableDnsRebindingProtection ?? false;
|
| 71 |
+
this._retryInterval = options.retryInterval;
|
| 72 |
+
}
|
| 73 |
+
/**
|
| 74 |
+
* Starts the transport. This is required by the Transport interface but is a no-op
|
| 75 |
+
* for the Streamable HTTP transport as connections are managed per-request.
|
| 76 |
+
*/
|
| 77 |
+
async start() {
|
| 78 |
+
if (this._started) {
|
| 79 |
+
throw new Error('Transport already started');
|
| 80 |
+
}
|
| 81 |
+
this._started = true;
|
| 82 |
+
}
|
| 83 |
+
/**
|
| 84 |
+
* Helper to create a JSON error response
|
| 85 |
+
*/
|
| 86 |
+
createJsonErrorResponse(status, code, message, options) {
|
| 87 |
+
const error = { code, message };
|
| 88 |
+
if (options?.data !== undefined) {
|
| 89 |
+
error.data = options.data;
|
| 90 |
+
}
|
| 91 |
+
return new Response(JSON.stringify({
|
| 92 |
+
jsonrpc: '2.0',
|
| 93 |
+
error,
|
| 94 |
+
id: null
|
| 95 |
+
}), {
|
| 96 |
+
status,
|
| 97 |
+
headers: {
|
| 98 |
+
'Content-Type': 'application/json',
|
| 99 |
+
...options?.headers
|
| 100 |
+
}
|
| 101 |
+
});
|
| 102 |
+
}
|
| 103 |
+
/**
|
| 104 |
+
* Validates request headers for DNS rebinding protection.
|
| 105 |
+
* @returns Error response if validation fails, undefined if validation passes.
|
| 106 |
+
*/
|
| 107 |
+
validateRequestHeaders(req) {
|
| 108 |
+
// Skip validation if protection is not enabled
|
| 109 |
+
if (!this._enableDnsRebindingProtection) {
|
| 110 |
+
return undefined;
|
| 111 |
+
}
|
| 112 |
+
// Validate Host header if allowedHosts is configured
|
| 113 |
+
if (this._allowedHosts && this._allowedHosts.length > 0) {
|
| 114 |
+
const hostHeader = req.headers.get('host');
|
| 115 |
+
if (!hostHeader || !this._allowedHosts.includes(hostHeader)) {
|
| 116 |
+
const error = `Invalid Host header: ${hostHeader}`;
|
| 117 |
+
this.onerror?.(new Error(error));
|
| 118 |
+
return this.createJsonErrorResponse(403, -32000, error);
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
// Validate Origin header if allowedOrigins is configured
|
| 122 |
+
if (this._allowedOrigins && this._allowedOrigins.length > 0) {
|
| 123 |
+
const originHeader = req.headers.get('origin');
|
| 124 |
+
if (originHeader && !this._allowedOrigins.includes(originHeader)) {
|
| 125 |
+
const error = `Invalid Origin header: ${originHeader}`;
|
| 126 |
+
this.onerror?.(new Error(error));
|
| 127 |
+
return this.createJsonErrorResponse(403, -32000, error);
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
return undefined;
|
| 131 |
+
}
|
| 132 |
+
/**
|
| 133 |
+
* Handles an incoming HTTP request, whether GET, POST, or DELETE
|
| 134 |
+
* Returns a Response object (Web Standard)
|
| 135 |
+
*/
|
| 136 |
+
async handleRequest(req, options) {
|
| 137 |
+
// In stateless mode (no sessionIdGenerator), each request must use a fresh transport.
|
| 138 |
+
// Reusing a stateless transport causes message ID collisions between clients.
|
| 139 |
+
if (!this.sessionIdGenerator && this._hasHandledRequest) {
|
| 140 |
+
throw new Error('Stateless transport cannot be reused across requests. Create a new transport per request.');
|
| 141 |
+
}
|
| 142 |
+
this._hasHandledRequest = true;
|
| 143 |
+
// Validate request headers for DNS rebinding protection
|
| 144 |
+
const validationError = this.validateRequestHeaders(req);
|
| 145 |
+
if (validationError) {
|
| 146 |
+
return validationError;
|
| 147 |
+
}
|
| 148 |
+
switch (req.method) {
|
| 149 |
+
case 'POST':
|
| 150 |
+
return this.handlePostRequest(req, options);
|
| 151 |
+
case 'GET':
|
| 152 |
+
return this.handleGetRequest(req);
|
| 153 |
+
case 'DELETE':
|
| 154 |
+
return this.handleDeleteRequest(req);
|
| 155 |
+
default:
|
| 156 |
+
return this.handleUnsupportedRequest();
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
/**
|
| 160 |
+
* Writes a priming event to establish resumption capability.
|
| 161 |
+
* Only sends if eventStore is configured (opt-in for resumability) and
|
| 162 |
+
* the client's protocol version supports empty SSE data (>= 2025-11-25).
|
| 163 |
+
*/
|
| 164 |
+
async writePrimingEvent(controller, encoder, streamId, protocolVersion) {
|
| 165 |
+
if (!this._eventStore) {
|
| 166 |
+
return;
|
| 167 |
+
}
|
| 168 |
+
// Priming events have empty data which older clients cannot handle.
|
| 169 |
+
// Only send priming events to clients with protocol version >= 2025-11-25
|
| 170 |
+
// which includes the fix for handling empty SSE data.
|
| 171 |
+
if (protocolVersion < '2025-11-25') {
|
| 172 |
+
return;
|
| 173 |
+
}
|
| 174 |
+
const primingEventId = await this._eventStore.storeEvent(streamId, {});
|
| 175 |
+
let primingEvent = `id: ${primingEventId}\ndata: \n\n`;
|
| 176 |
+
if (this._retryInterval !== undefined) {
|
| 177 |
+
primingEvent = `id: ${primingEventId}\nretry: ${this._retryInterval}\ndata: \n\n`;
|
| 178 |
+
}
|
| 179 |
+
controller.enqueue(encoder.encode(primingEvent));
|
| 180 |
+
}
|
| 181 |
+
/**
|
| 182 |
+
* Handles GET requests for SSE stream
|
| 183 |
+
*/
|
| 184 |
+
async handleGetRequest(req) {
|
| 185 |
+
// The client MUST include an Accept header, listing text/event-stream as a supported content type.
|
| 186 |
+
const acceptHeader = req.headers.get('accept');
|
| 187 |
+
if (!acceptHeader?.includes('text/event-stream')) {
|
| 188 |
+
this.onerror?.(new Error('Not Acceptable: Client must accept text/event-stream'));
|
| 189 |
+
return this.createJsonErrorResponse(406, -32000, 'Not Acceptable: Client must accept text/event-stream');
|
| 190 |
+
}
|
| 191 |
+
// If an Mcp-Session-Id is returned by the server during initialization,
|
| 192 |
+
// clients using the Streamable HTTP transport MUST include it
|
| 193 |
+
// in the Mcp-Session-Id header on all of their subsequent HTTP requests.
|
| 194 |
+
const sessionError = this.validateSession(req);
|
| 195 |
+
if (sessionError) {
|
| 196 |
+
return sessionError;
|
| 197 |
+
}
|
| 198 |
+
const protocolError = this.validateProtocolVersion(req);
|
| 199 |
+
if (protocolError) {
|
| 200 |
+
return protocolError;
|
| 201 |
+
}
|
| 202 |
+
// Handle resumability: check for Last-Event-ID header
|
| 203 |
+
if (this._eventStore) {
|
| 204 |
+
const lastEventId = req.headers.get('last-event-id');
|
| 205 |
+
if (lastEventId) {
|
| 206 |
+
return this.replayEvents(lastEventId);
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
// Check if there's already an active standalone SSE stream for this session
|
| 210 |
+
if (this._streamMapping.get(this._standaloneSseStreamId) !== undefined) {
|
| 211 |
+
// Only one GET SSE stream is allowed per session
|
| 212 |
+
this.onerror?.(new Error('Conflict: Only one SSE stream is allowed per session'));
|
| 213 |
+
return this.createJsonErrorResponse(409, -32000, 'Conflict: Only one SSE stream is allowed per session');
|
| 214 |
+
}
|
| 215 |
+
const encoder = new TextEncoder();
|
| 216 |
+
let streamController;
|
| 217 |
+
// Create a ReadableStream with a controller we can use to push SSE events
|
| 218 |
+
const readable = new ReadableStream({
|
| 219 |
+
start: controller => {
|
| 220 |
+
streamController = controller;
|
| 221 |
+
},
|
| 222 |
+
cancel: () => {
|
| 223 |
+
// Stream was cancelled by client
|
| 224 |
+
this._streamMapping.delete(this._standaloneSseStreamId);
|
| 225 |
+
}
|
| 226 |
+
});
|
| 227 |
+
const headers = {
|
| 228 |
+
'Content-Type': 'text/event-stream',
|
| 229 |
+
'Cache-Control': 'no-cache, no-transform',
|
| 230 |
+
Connection: 'keep-alive'
|
| 231 |
+
};
|
| 232 |
+
// After initialization, always include the session ID if we have one
|
| 233 |
+
if (this.sessionId !== undefined) {
|
| 234 |
+
headers['mcp-session-id'] = this.sessionId;
|
| 235 |
+
}
|
| 236 |
+
// Store the stream mapping with the controller for pushing data
|
| 237 |
+
this._streamMapping.set(this._standaloneSseStreamId, {
|
| 238 |
+
controller: streamController,
|
| 239 |
+
encoder,
|
| 240 |
+
cleanup: () => {
|
| 241 |
+
this._streamMapping.delete(this._standaloneSseStreamId);
|
| 242 |
+
try {
|
| 243 |
+
streamController.close();
|
| 244 |
+
}
|
| 245 |
+
catch {
|
| 246 |
+
// Controller might already be closed
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
});
|
| 250 |
+
return new Response(readable, { headers });
|
| 251 |
+
}
|
| 252 |
+
/**
|
| 253 |
+
* Replays events that would have been sent after the specified event ID
|
| 254 |
+
* Only used when resumability is enabled
|
| 255 |
+
*/
|
| 256 |
+
async replayEvents(lastEventId) {
|
| 257 |
+
if (!this._eventStore) {
|
| 258 |
+
this.onerror?.(new Error('Event store not configured'));
|
| 259 |
+
return this.createJsonErrorResponse(400, -32000, 'Event store not configured');
|
| 260 |
+
}
|
| 261 |
+
try {
|
| 262 |
+
// If getStreamIdForEventId is available, use it for conflict checking
|
| 263 |
+
let streamId;
|
| 264 |
+
if (this._eventStore.getStreamIdForEventId) {
|
| 265 |
+
streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
|
| 266 |
+
if (!streamId) {
|
| 267 |
+
this.onerror?.(new Error('Invalid event ID format'));
|
| 268 |
+
return this.createJsonErrorResponse(400, -32000, 'Invalid event ID format');
|
| 269 |
+
}
|
| 270 |
+
// Check conflict with the SAME streamId we'll use for mapping
|
| 271 |
+
if (this._streamMapping.get(streamId) !== undefined) {
|
| 272 |
+
this.onerror?.(new Error('Conflict: Stream already has an active connection'));
|
| 273 |
+
return this.createJsonErrorResponse(409, -32000, 'Conflict: Stream already has an active connection');
|
| 274 |
+
}
|
| 275 |
+
}
|
| 276 |
+
const headers = {
|
| 277 |
+
'Content-Type': 'text/event-stream',
|
| 278 |
+
'Cache-Control': 'no-cache, no-transform',
|
| 279 |
+
Connection: 'keep-alive'
|
| 280 |
+
};
|
| 281 |
+
if (this.sessionId !== undefined) {
|
| 282 |
+
headers['mcp-session-id'] = this.sessionId;
|
| 283 |
+
}
|
| 284 |
+
// Create a ReadableStream with controller for SSE
|
| 285 |
+
const encoder = new TextEncoder();
|
| 286 |
+
let streamController;
|
| 287 |
+
const readable = new ReadableStream({
|
| 288 |
+
start: controller => {
|
| 289 |
+
streamController = controller;
|
| 290 |
+
},
|
| 291 |
+
cancel: () => {
|
| 292 |
+
// Stream was cancelled by client
|
| 293 |
+
// Cleanup will be handled by the mapping
|
| 294 |
+
}
|
| 295 |
+
});
|
| 296 |
+
// Replay events - returns the streamId for backwards compatibility
|
| 297 |
+
const replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, {
|
| 298 |
+
send: async (eventId, message) => {
|
| 299 |
+
const success = this.writeSSEEvent(streamController, encoder, message, eventId);
|
| 300 |
+
if (!success) {
|
| 301 |
+
this.onerror?.(new Error('Failed replay events'));
|
| 302 |
+
try {
|
| 303 |
+
streamController.close();
|
| 304 |
+
}
|
| 305 |
+
catch {
|
| 306 |
+
// Controller might already be closed
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
});
|
| 311 |
+
this._streamMapping.set(replayedStreamId, {
|
| 312 |
+
controller: streamController,
|
| 313 |
+
encoder,
|
| 314 |
+
cleanup: () => {
|
| 315 |
+
this._streamMapping.delete(replayedStreamId);
|
| 316 |
+
try {
|
| 317 |
+
streamController.close();
|
| 318 |
+
}
|
| 319 |
+
catch {
|
| 320 |
+
// Controller might already be closed
|
| 321 |
+
}
|
| 322 |
+
}
|
| 323 |
+
});
|
| 324 |
+
return new Response(readable, { headers });
|
| 325 |
+
}
|
| 326 |
+
catch (error) {
|
| 327 |
+
this.onerror?.(error);
|
| 328 |
+
return this.createJsonErrorResponse(500, -32000, 'Error replaying events');
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
/**
|
| 332 |
+
* Writes an event to an SSE stream via controller with proper formatting
|
| 333 |
+
*/
|
| 334 |
+
writeSSEEvent(controller, encoder, message, eventId) {
|
| 335 |
+
try {
|
| 336 |
+
let eventData = `event: message\n`;
|
| 337 |
+
// Include event ID if provided - this is important for resumability
|
| 338 |
+
if (eventId) {
|
| 339 |
+
eventData += `id: ${eventId}\n`;
|
| 340 |
+
}
|
| 341 |
+
eventData += `data: ${JSON.stringify(message)}\n\n`;
|
| 342 |
+
controller.enqueue(encoder.encode(eventData));
|
| 343 |
+
return true;
|
| 344 |
+
}
|
| 345 |
+
catch (error) {
|
| 346 |
+
this.onerror?.(error);
|
| 347 |
+
return false;
|
| 348 |
+
}
|
| 349 |
+
}
|
| 350 |
+
/**
|
| 351 |
+
* Handles unsupported requests (PUT, PATCH, etc.)
|
| 352 |
+
*/
|
| 353 |
+
handleUnsupportedRequest() {
|
| 354 |
+
this.onerror?.(new Error('Method not allowed.'));
|
| 355 |
+
return new Response(JSON.stringify({
|
| 356 |
+
jsonrpc: '2.0',
|
| 357 |
+
error: {
|
| 358 |
+
code: -32000,
|
| 359 |
+
message: 'Method not allowed.'
|
| 360 |
+
},
|
| 361 |
+
id: null
|
| 362 |
+
}), {
|
| 363 |
+
status: 405,
|
| 364 |
+
headers: {
|
| 365 |
+
Allow: 'GET, POST, DELETE',
|
| 366 |
+
'Content-Type': 'application/json'
|
| 367 |
+
}
|
| 368 |
+
});
|
| 369 |
+
}
|
| 370 |
+
/**
|
| 371 |
+
* Handles POST requests containing JSON-RPC messages
|
| 372 |
+
*/
|
| 373 |
+
async handlePostRequest(req, options) {
|
| 374 |
+
try {
|
| 375 |
+
// Validate the Accept header
|
| 376 |
+
const acceptHeader = req.headers.get('accept');
|
| 377 |
+
// The client MUST include an Accept header, listing both application/json and text/event-stream as supported content types.
|
| 378 |
+
if (!acceptHeader?.includes('application/json') || !acceptHeader.includes('text/event-stream')) {
|
| 379 |
+
this.onerror?.(new Error('Not Acceptable: Client must accept both application/json and text/event-stream'));
|
| 380 |
+
return this.createJsonErrorResponse(406, -32000, 'Not Acceptable: Client must accept both application/json and text/event-stream');
|
| 381 |
+
}
|
| 382 |
+
const ct = req.headers.get('content-type');
|
| 383 |
+
if (!ct || !ct.includes('application/json')) {
|
| 384 |
+
this.onerror?.(new Error('Unsupported Media Type: Content-Type must be application/json'));
|
| 385 |
+
return this.createJsonErrorResponse(415, -32000, 'Unsupported Media Type: Content-Type must be application/json');
|
| 386 |
+
}
|
| 387 |
+
// Build request info from headers and URL
|
| 388 |
+
const requestInfo = {
|
| 389 |
+
headers: Object.fromEntries(req.headers.entries()),
|
| 390 |
+
url: new URL(req.url)
|
| 391 |
+
};
|
| 392 |
+
let rawMessage;
|
| 393 |
+
if (options?.parsedBody !== undefined) {
|
| 394 |
+
rawMessage = options.parsedBody;
|
| 395 |
+
}
|
| 396 |
+
else {
|
| 397 |
+
try {
|
| 398 |
+
rawMessage = await req.json();
|
| 399 |
+
}
|
| 400 |
+
catch {
|
| 401 |
+
this.onerror?.(new Error('Parse error: Invalid JSON'));
|
| 402 |
+
return this.createJsonErrorResponse(400, -32700, 'Parse error: Invalid JSON');
|
| 403 |
+
}
|
| 404 |
+
}
|
| 405 |
+
let messages;
|
| 406 |
+
// handle batch and single messages
|
| 407 |
+
try {
|
| 408 |
+
if (Array.isArray(rawMessage)) {
|
| 409 |
+
messages = rawMessage.map(msg => JSONRPCMessageSchema.parse(msg));
|
| 410 |
+
}
|
| 411 |
+
else {
|
| 412 |
+
messages = [JSONRPCMessageSchema.parse(rawMessage)];
|
| 413 |
+
}
|
| 414 |
+
}
|
| 415 |
+
catch {
|
| 416 |
+
this.onerror?.(new Error('Parse error: Invalid JSON-RPC message'));
|
| 417 |
+
return this.createJsonErrorResponse(400, -32700, 'Parse error: Invalid JSON-RPC message');
|
| 418 |
+
}
|
| 419 |
+
// Check if this is an initialization request
|
| 420 |
+
// https://spec.modelcontextprotocol.io/specification/2025-03-26/basic/lifecycle/
|
| 421 |
+
const isInitializationRequest = messages.some(isInitializeRequest);
|
| 422 |
+
if (isInitializationRequest) {
|
| 423 |
+
// If it's a server with session management and the session ID is already set we should reject the request
|
| 424 |
+
// to avoid re-initialization.
|
| 425 |
+
if (this._initialized && this.sessionId !== undefined) {
|
| 426 |
+
this.onerror?.(new Error('Invalid Request: Server already initialized'));
|
| 427 |
+
return this.createJsonErrorResponse(400, -32600, 'Invalid Request: Server already initialized');
|
| 428 |
+
}
|
| 429 |
+
if (messages.length > 1) {
|
| 430 |
+
this.onerror?.(new Error('Invalid Request: Only one initialization request is allowed'));
|
| 431 |
+
return this.createJsonErrorResponse(400, -32600, 'Invalid Request: Only one initialization request is allowed');
|
| 432 |
+
}
|
| 433 |
+
this.sessionId = this.sessionIdGenerator?.();
|
| 434 |
+
this._initialized = true;
|
| 435 |
+
// If we have a session ID and an onsessioninitialized handler, call it immediately
|
| 436 |
+
// This is needed in cases where the server needs to keep track of multiple sessions
|
| 437 |
+
if (this.sessionId && this._onsessioninitialized) {
|
| 438 |
+
await Promise.resolve(this._onsessioninitialized(this.sessionId));
|
| 439 |
+
}
|
| 440 |
+
}
|
| 441 |
+
if (!isInitializationRequest) {
|
| 442 |
+
// If an Mcp-Session-Id is returned by the server during initialization,
|
| 443 |
+
// clients using the Streamable HTTP transport MUST include it
|
| 444 |
+
// in the Mcp-Session-Id header on all of their subsequent HTTP requests.
|
| 445 |
+
const sessionError = this.validateSession(req);
|
| 446 |
+
if (sessionError) {
|
| 447 |
+
return sessionError;
|
| 448 |
+
}
|
| 449 |
+
// Mcp-Protocol-Version header is required for all requests after initialization.
|
| 450 |
+
const protocolError = this.validateProtocolVersion(req);
|
| 451 |
+
if (protocolError) {
|
| 452 |
+
return protocolError;
|
| 453 |
+
}
|
| 454 |
+
}
|
| 455 |
+
// check if it contains requests
|
| 456 |
+
const hasRequests = messages.some(isJSONRPCRequest);
|
| 457 |
+
if (!hasRequests) {
|
| 458 |
+
// if it only contains notifications or responses, return 202
|
| 459 |
+
for (const message of messages) {
|
| 460 |
+
this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo });
|
| 461 |
+
}
|
| 462 |
+
return new Response(null, { status: 202 });
|
| 463 |
+
}
|
| 464 |
+
// The default behavior is to use SSE streaming
|
| 465 |
+
// but in some cases server will return JSON responses
|
| 466 |
+
const streamId = crypto.randomUUID();
|
| 467 |
+
// Extract protocol version for priming event decision.
|
| 468 |
+
// For initialize requests, get from request params.
|
| 469 |
+
// For other requests, get from header (already validated).
|
| 470 |
+
const initRequest = messages.find(m => isInitializeRequest(m));
|
| 471 |
+
const clientProtocolVersion = initRequest
|
| 472 |
+
? initRequest.params.protocolVersion
|
| 473 |
+
: (req.headers.get('mcp-protocol-version') ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION);
|
| 474 |
+
if (this._enableJsonResponse) {
|
| 475 |
+
// For JSON response mode, return a Promise that resolves when all responses are ready
|
| 476 |
+
return new Promise(resolve => {
|
| 477 |
+
this._streamMapping.set(streamId, {
|
| 478 |
+
resolveJson: resolve,
|
| 479 |
+
cleanup: () => {
|
| 480 |
+
this._streamMapping.delete(streamId);
|
| 481 |
+
}
|
| 482 |
+
});
|
| 483 |
+
for (const message of messages) {
|
| 484 |
+
if (isJSONRPCRequest(message)) {
|
| 485 |
+
this._requestToStreamMapping.set(message.id, streamId);
|
| 486 |
+
}
|
| 487 |
+
}
|
| 488 |
+
for (const message of messages) {
|
| 489 |
+
this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo });
|
| 490 |
+
}
|
| 491 |
+
});
|
| 492 |
+
}
|
| 493 |
+
// SSE streaming mode - use ReadableStream with controller for more reliable data pushing
|
| 494 |
+
const encoder = new TextEncoder();
|
| 495 |
+
let streamController;
|
| 496 |
+
const readable = new ReadableStream({
|
| 497 |
+
start: controller => {
|
| 498 |
+
streamController = controller;
|
| 499 |
+
},
|
| 500 |
+
cancel: () => {
|
| 501 |
+
// Stream was cancelled by client
|
| 502 |
+
this._streamMapping.delete(streamId);
|
| 503 |
+
}
|
| 504 |
+
});
|
| 505 |
+
const headers = {
|
| 506 |
+
'Content-Type': 'text/event-stream',
|
| 507 |
+
'Cache-Control': 'no-cache',
|
| 508 |
+
Connection: 'keep-alive'
|
| 509 |
+
};
|
| 510 |
+
// After initialization, always include the session ID if we have one
|
| 511 |
+
if (this.sessionId !== undefined) {
|
| 512 |
+
headers['mcp-session-id'] = this.sessionId;
|
| 513 |
+
}
|
| 514 |
+
// Store the response for this request to send messages back through this connection
|
| 515 |
+
// We need to track by request ID to maintain the connection
|
| 516 |
+
for (const message of messages) {
|
| 517 |
+
if (isJSONRPCRequest(message)) {
|
| 518 |
+
this._streamMapping.set(streamId, {
|
| 519 |
+
controller: streamController,
|
| 520 |
+
encoder,
|
| 521 |
+
cleanup: () => {
|
| 522 |
+
this._streamMapping.delete(streamId);
|
| 523 |
+
try {
|
| 524 |
+
streamController.close();
|
| 525 |
+
}
|
| 526 |
+
catch {
|
| 527 |
+
// Controller might already be closed
|
| 528 |
+
}
|
| 529 |
+
}
|
| 530 |
+
});
|
| 531 |
+
this._requestToStreamMapping.set(message.id, streamId);
|
| 532 |
+
}
|
| 533 |
+
}
|
| 534 |
+
// Write priming event if event store is configured (after mapping is set up)
|
| 535 |
+
await this.writePrimingEvent(streamController, encoder, streamId, clientProtocolVersion);
|
| 536 |
+
// handle each message
|
| 537 |
+
for (const message of messages) {
|
| 538 |
+
// Build closeSSEStream callback for requests when eventStore is configured
|
| 539 |
+
// AND client supports resumability (protocol version >= 2025-11-25).
|
| 540 |
+
// Old clients can't resume if the stream is closed early because they
|
| 541 |
+
// didn't receive a priming event with an event ID.
|
| 542 |
+
let closeSSEStream;
|
| 543 |
+
let closeStandaloneSSEStream;
|
| 544 |
+
if (isJSONRPCRequest(message) && this._eventStore && clientProtocolVersion >= '2025-11-25') {
|
| 545 |
+
closeSSEStream = () => {
|
| 546 |
+
this.closeSSEStream(message.id);
|
| 547 |
+
};
|
| 548 |
+
closeStandaloneSSEStream = () => {
|
| 549 |
+
this.closeStandaloneSSEStream();
|
| 550 |
+
};
|
| 551 |
+
}
|
| 552 |
+
this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo, closeSSEStream, closeStandaloneSSEStream });
|
| 553 |
+
}
|
| 554 |
+
// The server SHOULD NOT close the SSE stream before sending all JSON-RPC responses
|
| 555 |
+
// This will be handled by the send() method when responses are ready
|
| 556 |
+
return new Response(readable, { status: 200, headers });
|
| 557 |
+
}
|
| 558 |
+
catch (error) {
|
| 559 |
+
// return JSON-RPC formatted error
|
| 560 |
+
this.onerror?.(error);
|
| 561 |
+
return this.createJsonErrorResponse(400, -32700, 'Parse error', { data: String(error) });
|
| 562 |
+
}
|
| 563 |
+
}
|
| 564 |
+
/**
|
| 565 |
+
* Handles DELETE requests to terminate sessions
|
| 566 |
+
*/
|
| 567 |
+
async handleDeleteRequest(req) {
|
| 568 |
+
const sessionError = this.validateSession(req);
|
| 569 |
+
if (sessionError) {
|
| 570 |
+
return sessionError;
|
| 571 |
+
}
|
| 572 |
+
const protocolError = this.validateProtocolVersion(req);
|
| 573 |
+
if (protocolError) {
|
| 574 |
+
return protocolError;
|
| 575 |
+
}
|
| 576 |
+
await Promise.resolve(this._onsessionclosed?.(this.sessionId));
|
| 577 |
+
await this.close();
|
| 578 |
+
return new Response(null, { status: 200 });
|
| 579 |
+
}
|
| 580 |
+
/**
|
| 581 |
+
* Validates session ID for non-initialization requests.
|
| 582 |
+
* Returns Response error if invalid, undefined otherwise
|
| 583 |
+
*/
|
| 584 |
+
validateSession(req) {
|
| 585 |
+
if (this.sessionIdGenerator === undefined) {
|
| 586 |
+
// If the sessionIdGenerator ID is not set, the session management is disabled
|
| 587 |
+
// and we don't need to validate the session ID
|
| 588 |
+
return undefined;
|
| 589 |
+
}
|
| 590 |
+
if (!this._initialized) {
|
| 591 |
+
// If the server has not been initialized yet, reject all requests
|
| 592 |
+
this.onerror?.(new Error('Bad Request: Server not initialized'));
|
| 593 |
+
return this.createJsonErrorResponse(400, -32000, 'Bad Request: Server not initialized');
|
| 594 |
+
}
|
| 595 |
+
const sessionId = req.headers.get('mcp-session-id');
|
| 596 |
+
if (!sessionId) {
|
| 597 |
+
// Non-initialization requests without a session ID should return 400 Bad Request
|
| 598 |
+
this.onerror?.(new Error('Bad Request: Mcp-Session-Id header is required'));
|
| 599 |
+
return this.createJsonErrorResponse(400, -32000, 'Bad Request: Mcp-Session-Id header is required');
|
| 600 |
+
}
|
| 601 |
+
if (sessionId !== this.sessionId) {
|
| 602 |
+
// Reject requests with invalid session ID with 404 Not Found
|
| 603 |
+
this.onerror?.(new Error('Session not found'));
|
| 604 |
+
return this.createJsonErrorResponse(404, -32001, 'Session not found');
|
| 605 |
+
}
|
| 606 |
+
return undefined;
|
| 607 |
+
}
|
| 608 |
+
/**
|
| 609 |
+
* Validates the MCP-Protocol-Version header on incoming requests.
|
| 610 |
+
*
|
| 611 |
+
* For initialization: Version negotiation handles unknown versions gracefully
|
| 612 |
+
* (server responds with its supported version).
|
| 613 |
+
*
|
| 614 |
+
* For subsequent requests with MCP-Protocol-Version header:
|
| 615 |
+
* - Accept if in supported list
|
| 616 |
+
* - 400 if unsupported
|
| 617 |
+
*
|
| 618 |
+
* For HTTP requests without the MCP-Protocol-Version header:
|
| 619 |
+
* - Accept and default to the version negotiated at initialization
|
| 620 |
+
*/
|
| 621 |
+
validateProtocolVersion(req) {
|
| 622 |
+
const protocolVersion = req.headers.get('mcp-protocol-version');
|
| 623 |
+
if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
|
| 624 |
+
this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion}` +
|
| 625 |
+
` (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(', ')})`));
|
| 626 |
+
return this.createJsonErrorResponse(400, -32000, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(', ')})`);
|
| 627 |
+
}
|
| 628 |
+
return undefined;
|
| 629 |
+
}
|
| 630 |
+
async close() {
|
| 631 |
+
// Close all SSE connections
|
| 632 |
+
this._streamMapping.forEach(({ cleanup }) => {
|
| 633 |
+
cleanup();
|
| 634 |
+
});
|
| 635 |
+
this._streamMapping.clear();
|
| 636 |
+
// Clear any pending responses
|
| 637 |
+
this._requestResponseMap.clear();
|
| 638 |
+
this.onclose?.();
|
| 639 |
+
}
|
| 640 |
+
/**
|
| 641 |
+
* Close an SSE stream for a specific request, triggering client reconnection.
|
| 642 |
+
* Use this to implement polling behavior during long-running operations -
|
| 643 |
+
* client will reconnect after the retry interval specified in the priming event.
|
| 644 |
+
*/
|
| 645 |
+
closeSSEStream(requestId) {
|
| 646 |
+
const streamId = this._requestToStreamMapping.get(requestId);
|
| 647 |
+
if (!streamId)
|
| 648 |
+
return;
|
| 649 |
+
const stream = this._streamMapping.get(streamId);
|
| 650 |
+
if (stream) {
|
| 651 |
+
stream.cleanup();
|
| 652 |
+
}
|
| 653 |
+
}
|
| 654 |
+
/**
|
| 655 |
+
* Close the standalone GET SSE stream, triggering client reconnection.
|
| 656 |
+
* Use this to implement polling behavior for server-initiated notifications.
|
| 657 |
+
*/
|
| 658 |
+
closeStandaloneSSEStream() {
|
| 659 |
+
const stream = this._streamMapping.get(this._standaloneSseStreamId);
|
| 660 |
+
if (stream) {
|
| 661 |
+
stream.cleanup();
|
| 662 |
+
}
|
| 663 |
+
}
|
| 664 |
+
async send(message, options) {
|
| 665 |
+
let requestId = options?.relatedRequestId;
|
| 666 |
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
| 667 |
+
// If the message is a response, use the request ID from the message
|
| 668 |
+
requestId = message.id;
|
| 669 |
+
}
|
| 670 |
+
// Check if this message should be sent on the standalone SSE stream (no request ID)
|
| 671 |
+
// Ignore notifications from tools (which have relatedRequestId set)
|
| 672 |
+
// Those will be sent via dedicated response SSE streams
|
| 673 |
+
if (requestId === undefined) {
|
| 674 |
+
// For standalone SSE streams, we can only send requests and notifications
|
| 675 |
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
| 676 |
+
throw new Error('Cannot send a response on a standalone SSE stream unless resuming a previous client request');
|
| 677 |
+
}
|
| 678 |
+
// Generate and store event ID if event store is provided
|
| 679 |
+
// Store even if stream is disconnected so events can be replayed on reconnect
|
| 680 |
+
let eventId;
|
| 681 |
+
if (this._eventStore) {
|
| 682 |
+
// Stores the event and gets the generated event ID
|
| 683 |
+
eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message);
|
| 684 |
+
}
|
| 685 |
+
const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId);
|
| 686 |
+
if (standaloneSse === undefined) {
|
| 687 |
+
// Stream is disconnected - event is stored for replay, nothing more to do
|
| 688 |
+
return;
|
| 689 |
+
}
|
| 690 |
+
// Send the message to the standalone SSE stream
|
| 691 |
+
if (standaloneSse.controller && standaloneSse.encoder) {
|
| 692 |
+
this.writeSSEEvent(standaloneSse.controller, standaloneSse.encoder, message, eventId);
|
| 693 |
+
}
|
| 694 |
+
return;
|
| 695 |
+
}
|
| 696 |
+
// Get the response for this request
|
| 697 |
+
const streamId = this._requestToStreamMapping.get(requestId);
|
| 698 |
+
if (!streamId) {
|
| 699 |
+
throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
| 700 |
+
}
|
| 701 |
+
const stream = this._streamMapping.get(streamId);
|
| 702 |
+
if (!this._enableJsonResponse && stream?.controller && stream?.encoder) {
|
| 703 |
+
// For SSE responses, generate event ID if event store is provided
|
| 704 |
+
let eventId;
|
| 705 |
+
if (this._eventStore) {
|
| 706 |
+
eventId = await this._eventStore.storeEvent(streamId, message);
|
| 707 |
+
}
|
| 708 |
+
// Write the event to the response stream
|
| 709 |
+
this.writeSSEEvent(stream.controller, stream.encoder, message, eventId);
|
| 710 |
+
}
|
| 711 |
+
if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
|
| 712 |
+
this._requestResponseMap.set(requestId, message);
|
| 713 |
+
const relatedIds = Array.from(this._requestToStreamMapping.entries())
|
| 714 |
+
.filter(([_, sid]) => sid === streamId)
|
| 715 |
+
.map(([id]) => id);
|
| 716 |
+
// Check if we have responses for all requests using this connection
|
| 717 |
+
const allResponsesReady = relatedIds.every(id => this._requestResponseMap.has(id));
|
| 718 |
+
if (allResponsesReady) {
|
| 719 |
+
if (!stream) {
|
| 720 |
+
throw new Error(`No connection established for request ID: ${String(requestId)}`);
|
| 721 |
+
}
|
| 722 |
+
if (this._enableJsonResponse && stream.resolveJson) {
|
| 723 |
+
// All responses ready, send as JSON
|
| 724 |
+
const headers = {
|
| 725 |
+
'Content-Type': 'application/json'
|
| 726 |
+
};
|
| 727 |
+
if (this.sessionId !== undefined) {
|
| 728 |
+
headers['mcp-session-id'] = this.sessionId;
|
| 729 |
+
}
|
| 730 |
+
const responses = relatedIds.map(id => this._requestResponseMap.get(id));
|
| 731 |
+
if (responses.length === 1) {
|
| 732 |
+
stream.resolveJson(new Response(JSON.stringify(responses[0]), { status: 200, headers }));
|
| 733 |
+
}
|
| 734 |
+
else {
|
| 735 |
+
stream.resolveJson(new Response(JSON.stringify(responses), { status: 200, headers }));
|
| 736 |
+
}
|
| 737 |
+
}
|
| 738 |
+
else {
|
| 739 |
+
// End the SSE stream
|
| 740 |
+
stream.cleanup();
|
| 741 |
+
}
|
| 742 |
+
// Clean up
|
| 743 |
+
for (const id of relatedIds) {
|
| 744 |
+
this._requestResponseMap.delete(id);
|
| 745 |
+
this._requestToStreamMapping.delete(id);
|
| 746 |
+
}
|
| 747 |
+
}
|
| 748 |
+
}
|
| 749 |
+
}
|
| 750 |
+
}
|
| 751 |
+
//# sourceMappingURL=webStandardStreamableHttp.js.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js.map
ADDED
|
@@ -0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CAAC;gBACD,WAAW;gBACX,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;oBAC1B,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;oBACpC,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAC5C,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type * as z3 from 'zod/v3';
|
| 2 |
+
import type * as z4 from 'zod/v4/core';
|
| 3 |
+
export type AnySchema = z3.ZodTypeAny | z4.$ZodType;
|
| 4 |
+
export type AnyObjectSchema = z3.AnyZodObject | z4.$ZodObject | AnySchema;
|
| 5 |
+
export type ZodRawShapeCompat = Record<string, AnySchema>;
|
| 6 |
+
export interface ZodV3Internal {
|
| 7 |
+
_def?: {
|
| 8 |
+
typeName?: string;
|
| 9 |
+
value?: unknown;
|
| 10 |
+
values?: unknown[];
|
| 11 |
+
shape?: Record<string, AnySchema> | (() => Record<string, AnySchema>);
|
| 12 |
+
description?: string;
|
| 13 |
+
};
|
| 14 |
+
shape?: Record<string, AnySchema> | (() => Record<string, AnySchema>);
|
| 15 |
+
value?: unknown;
|
| 16 |
+
}
|
| 17 |
+
export interface ZodV4Internal {
|
| 18 |
+
_zod?: {
|
| 19 |
+
def?: {
|
| 20 |
+
type?: string;
|
| 21 |
+
value?: unknown;
|
| 22 |
+
values?: unknown[];
|
| 23 |
+
shape?: Record<string, AnySchema> | (() => Record<string, AnySchema>);
|
| 24 |
+
};
|
| 25 |
+
};
|
| 26 |
+
value?: unknown;
|
| 27 |
+
}
|
| 28 |
+
export type SchemaOutput<S> = S extends z3.ZodTypeAny ? z3.infer<S> : S extends z4.$ZodType ? z4.output<S> : never;
|
| 29 |
+
export type SchemaInput<S> = S extends z3.ZodTypeAny ? z3.input<S> : S extends z4.$ZodType ? z4.input<S> : never;
|
| 30 |
+
/**
|
| 31 |
+
* Infers the output type from a ZodRawShapeCompat (raw shape object).
|
| 32 |
+
* Maps over each key in the shape and infers the output type from each schema.
|
| 33 |
+
*/
|
| 34 |
+
export type ShapeOutput<Shape extends ZodRawShapeCompat> = {
|
| 35 |
+
[K in keyof Shape]: SchemaOutput<Shape[K]>;
|
| 36 |
+
};
|
| 37 |
+
export declare function isZ4Schema(s: AnySchema): s is z4.$ZodType;
|
| 38 |
+
export declare function objectFromShape(shape: ZodRawShapeCompat): AnyObjectSchema;
|
| 39 |
+
export declare function safeParse<S extends AnySchema>(schema: S, data: unknown): {
|
| 40 |
+
success: true;
|
| 41 |
+
data: SchemaOutput<S>;
|
| 42 |
+
} | {
|
| 43 |
+
success: false;
|
| 44 |
+
error: unknown;
|
| 45 |
+
};
|
| 46 |
+
export declare function safeParseAsync<S extends AnySchema>(schema: S, data: unknown): Promise<{
|
| 47 |
+
success: true;
|
| 48 |
+
data: SchemaOutput<S>;
|
| 49 |
+
} | {
|
| 50 |
+
success: false;
|
| 51 |
+
error: unknown;
|
| 52 |
+
}>;
|
| 53 |
+
export declare function getObjectShape(schema: AnyObjectSchema | undefined): Record<string, AnySchema> | undefined;
|
| 54 |
+
/**
|
| 55 |
+
* Normalizes a schema to an object schema. Handles both:
|
| 56 |
+
* - Already-constructed object schemas (v3 or v4)
|
| 57 |
+
* - Raw shapes that need to be wrapped into object schemas
|
| 58 |
+
*/
|
| 59 |
+
export declare function normalizeObjectSchema(schema: AnySchema | ZodRawShapeCompat | undefined): AnyObjectSchema | undefined;
|
| 60 |
+
/**
|
| 61 |
+
* Safely extracts an error message from a parse result error.
|
| 62 |
+
* Zod errors can have different structures, so we handle various cases.
|
| 63 |
+
*/
|
| 64 |
+
export declare function getParseErrorMessage(error: unknown): string;
|
| 65 |
+
/**
|
| 66 |
+
* Gets the description from a schema, if available.
|
| 67 |
+
* Works with both Zod v3 and v4.
|
| 68 |
+
*
|
| 69 |
+
* Both versions expose a `.description` getter that returns the description
|
| 70 |
+
* from their respective internal storage (v3: _def, v4: globalRegistry).
|
| 71 |
+
*/
|
| 72 |
+
export declare function getSchemaDescription(schema: AnySchema): string | undefined;
|
| 73 |
+
/**
|
| 74 |
+
* Checks if a schema is optional.
|
| 75 |
+
* Works with both Zod v3 and v4.
|
| 76 |
+
*/
|
| 77 |
+
export declare function isSchemaOptional(schema: AnySchema): boolean;
|
| 78 |
+
/**
|
| 79 |
+
* Gets the literal value from a schema, if it's a literal schema.
|
| 80 |
+
* Works with both Zod v3 and v4.
|
| 81 |
+
* Returns undefined if the schema is not a literal or the value cannot be determined.
|
| 82 |
+
*/
|
| 83 |
+
export declare function getLiteralValue(schema: AnySchema): unknown;
|
| 84 |
+
//# sourceMappingURL=zod-compat.d.ts.map
|
node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"version":3,"file":"zod-compat.d.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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// zod-compat.ts
|
| 2 |
+
// ----------------------------------------------------
|
| 3 |
+
// Unified types + helpers to accept Zod v3 and v4 (Mini)
|
| 4 |
+
// ----------------------------------------------------
|
| 5 |
+
import * as z3rt from 'zod/v3';
|
| 6 |
+
import * as z4mini from 'zod/v4-mini';
|
| 7 |
+
// --- Runtime detection ---
|
| 8 |
+
export function isZ4Schema(s) {
|
| 9 |
+
// Present on Zod 4 (Classic & Mini) schemas; absent on Zod 3
|
| 10 |
+
const schema = s;
|
| 11 |
+
return !!schema._zod;
|
| 12 |
+
}
|
| 13 |
+
// --- Schema construction ---
|
| 14 |
+
export function objectFromShape(shape) {
|
| 15 |
+
const values = Object.values(shape);
|
| 16 |
+
if (values.length === 0)
|
| 17 |
+
return z4mini.object({}); // default to v4 Mini
|
| 18 |
+
const allV4 = values.every(isZ4Schema);
|
| 19 |
+
const allV3 = values.every(s => !isZ4Schema(s));
|
| 20 |
+
if (allV4)
|
| 21 |
+
return z4mini.object(shape);
|
| 22 |
+
if (allV3)
|
| 23 |
+
return z3rt.object(shape);
|
| 24 |
+
throw new Error('Mixed Zod versions detected in object shape.');
|
| 25 |
+
}
|
| 26 |
+
// --- Unified parsing ---
|
| 27 |
+
export function safeParse(schema, data) {
|
| 28 |
+
if (isZ4Schema(schema)) {
|
| 29 |
+
// Mini exposes top-level safeParse
|
| 30 |
+
const result = z4mini.safeParse(schema, data);
|
| 31 |
+
return result;
|
| 32 |
+
}
|
| 33 |
+
const v3Schema = schema;
|
| 34 |
+
const result = v3Schema.safeParse(data);
|
| 35 |
+
return result;
|
| 36 |
+
}
|
| 37 |
+
export async function safeParseAsync(schema, data) {
|
| 38 |
+
if (isZ4Schema(schema)) {
|
| 39 |
+
// Mini exposes top-level safeParseAsync
|
| 40 |
+
const result = await z4mini.safeParseAsync(schema, data);
|
| 41 |
+
return result;
|
| 42 |
+
}
|
| 43 |
+
const v3Schema = schema;
|
| 44 |
+
const result = await v3Schema.safeParseAsync(data);
|
| 45 |
+
return result;
|
| 46 |
+
}
|
| 47 |
+
// --- Shape extraction ---
|
| 48 |
+
export function getObjectShape(schema) {
|
| 49 |
+
if (!schema)
|
| 50 |
+
return undefined;
|
| 51 |
+
// Zod v3 exposes `.shape`; Zod v4 keeps the shape on `_zod.def.shape`
|
| 52 |
+
let rawShape;
|
| 53 |
+
if (isZ4Schema(schema)) {
|
| 54 |
+
const v4Schema = schema;
|
| 55 |
+
rawShape = v4Schema._zod?.def?.shape;
|
| 56 |
+
}
|
| 57 |
+
else {
|
| 58 |
+
const v3Schema = schema;
|
| 59 |
+
rawShape = v3Schema.shape;
|
| 60 |
+
}
|
| 61 |
+
if (!rawShape)
|
| 62 |
+
return undefined;
|
| 63 |
+
if (typeof rawShape === 'function') {
|
| 64 |
+
try {
|
| 65 |
+
return rawShape();
|
| 66 |
+
}
|
| 67 |
+
catch {
|
| 68 |
+
return undefined;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
return rawShape;
|
| 72 |
+
}
|
| 73 |
+
// --- Schema normalization ---
|
| 74 |
+
/**
|
| 75 |
+
* Normalizes a schema to an object schema. Handles both:
|
| 76 |
+
* - Already-constructed object schemas (v3 or v4)
|
| 77 |
+
* - Raw shapes that need to be wrapped into object schemas
|
| 78 |
+
*/
|
| 79 |
+
export function normalizeObjectSchema(schema) {
|
| 80 |
+
if (!schema)
|
| 81 |
+
return undefined;
|
| 82 |
+
// First check if it's a raw shape (Record<string, AnySchema>)
|
| 83 |
+
// Raw shapes don't have _def or _zod properties and aren't schemas themselves
|
| 84 |
+
if (typeof schema === 'object') {
|
| 85 |
+
// Check if it's actually a ZodRawShapeCompat (not a schema instance)
|
| 86 |
+
// by checking if it lacks schema-like internal properties
|
| 87 |
+
const asV3 = schema;
|
| 88 |
+
const asV4 = schema;
|
| 89 |
+
// If it's not a schema instance (no _def or _zod), it might be a raw shape
|
| 90 |
+
if (!asV3._def && !asV4._zod) {
|
| 91 |
+
// Check if all values are schemas (heuristic to confirm it's a raw shape)
|
| 92 |
+
const values = Object.values(schema);
|
| 93 |
+
if (values.length > 0 &&
|
| 94 |
+
values.every(v => typeof v === 'object' &&
|
| 95 |
+
v !== null &&
|
| 96 |
+
(v._def !== undefined ||
|
| 97 |
+
v._zod !== undefined ||
|
| 98 |
+
typeof v.parse === 'function'))) {
|
| 99 |
+
return objectFromShape(schema);
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
// If we get here, it should be an AnySchema (not a raw shape)
|
| 104 |
+
// Check if it's already an object schema
|
| 105 |
+
if (isZ4Schema(schema)) {
|
| 106 |
+
// Check if it's a v4 object
|
| 107 |
+
const v4Schema = schema;
|
| 108 |
+
const def = v4Schema._zod?.def;
|
| 109 |
+
if (def && (def.type === 'object' || def.shape !== undefined)) {
|
| 110 |
+
return schema;
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
else {
|
| 114 |
+
// Check if it's a v3 object
|
| 115 |
+
const v3Schema = schema;
|
| 116 |
+
if (v3Schema.shape !== undefined) {
|
| 117 |
+
return schema;
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
return undefined;
|
| 121 |
+
}
|
| 122 |
+
// --- Error message extraction ---
|
| 123 |
+
/**
|
| 124 |
+
* Safely extracts an error message from a parse result error.
|
| 125 |
+
* Zod errors can have different structures, so we handle various cases.
|
| 126 |
+
*/
|
| 127 |
+
export function getParseErrorMessage(error) {
|
| 128 |
+
if (error && typeof error === 'object') {
|
| 129 |
+
// Try common error structures
|
| 130 |
+
if ('message' in error && typeof error.message === 'string') {
|
| 131 |
+
return error.message;
|
| 132 |
+
}
|
| 133 |
+
if ('issues' in error && Array.isArray(error.issues) && error.issues.length > 0) {
|
| 134 |
+
const firstIssue = error.issues[0];
|
| 135 |
+
if (firstIssue && typeof firstIssue === 'object' && 'message' in firstIssue) {
|
| 136 |
+
return String(firstIssue.message);
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
// Fallback: try to stringify the error
|
| 140 |
+
try {
|
| 141 |
+
return JSON.stringify(error);
|
| 142 |
+
}
|
| 143 |
+
catch {
|
| 144 |
+
return String(error);
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
return String(error);
|
| 148 |
+
}
|
| 149 |
+
// --- Schema metadata access ---
|
| 150 |
+
/**
|
| 151 |
+
* Gets the description from a schema, if available.
|
| 152 |
+
* Works with both Zod v3 and v4.
|
| 153 |
+
*
|
| 154 |
+
* Both versions expose a `.description` getter that returns the description
|
| 155 |
+
* from their respective internal storage (v3: _def, v4: globalRegistry).
|
| 156 |
+
*/
|
| 157 |
+
export function getSchemaDescription(schema) {
|
| 158 |
+
return schema.description;
|
| 159 |
+
}
|
| 160 |
+
/**
|
| 161 |
+
* Checks if a schema is optional.
|
| 162 |
+
* Works with both Zod v3 and v4.
|
| 163 |
+
*/
|
| 164 |
+
export function isSchemaOptional(schema) {
|
| 165 |
+
if (isZ4Schema(schema)) {
|
| 166 |
+
const v4Schema = schema;
|
| 167 |
+
return v4Schema._zod?.def?.type === 'optional';
|
| 168 |
+
}
|
| 169 |
+
const v3Schema = schema;
|
| 170 |
+
// v3 has isOptional() method
|
| 171 |
+
if (typeof schema.isOptional === 'function') {
|
| 172 |
+
return schema.isOptional();
|
| 173 |
+
}
|
| 174 |
+
return v3Schema._def?.typeName === 'ZodOptional';
|
| 175 |
+
}
|
| 176 |
+
/**
|
| 177 |
+
* Gets the literal value from a schema, if it's a literal schema.
|
| 178 |
+
* Works with both Zod v3 and v4.
|
| 179 |
+
* Returns undefined if the schema is not a literal or the value cannot be determined.
|
| 180 |
+
*/
|
| 181 |
+
export function getLiteralValue(schema) {
|
| 182 |
+
if (isZ4Schema(schema)) {
|
| 183 |
+
const v4Schema = schema;
|
| 184 |
+
const def = v4Schema._zod?.def;
|
| 185 |
+
if (def) {
|
| 186 |
+
// Try various ways to get the literal value
|
| 187 |
+
if (def.value !== undefined)
|
| 188 |
+
return def.value;
|
| 189 |
+
if (Array.isArray(def.values) && def.values.length > 0) {
|
| 190 |
+
return def.values[0];
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
const v3Schema = schema;
|
| 195 |
+
const def = v3Schema._def;
|
| 196 |
+
if (def) {
|
| 197 |
+
if (def.value !== undefined)
|
| 198 |
+
return def.value;
|
| 199 |
+
if (Array.isArray(def.values) && def.values.length > 0) {
|
| 200 |
+
return def.values[0];
|
| 201 |
+
}
|
| 202 |
+
}
|
| 203 |
+
// Fallback: check for direct value property (some Zod versions)
|
| 204 |
+
const directValue = schema.value;
|
| 205 |
+
if (directValue !== undefined)
|
| 206 |
+
return directValue;
|
| 207 |
+
return undefined;
|
| 208 |
+
}
|
| 209 |
+
//# sourceMappingURL=zod-compat.js.map
|