@cyanheads/pubmed-mcp-server 1.1.4 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -12
- package/dist/mcp-server/server.d.ts +0 -7
- package/dist/mcp-server/server.js +17 -53
- package/dist/mcp-server/tools/fetchPubMedContent/logic.d.ts +6 -2
- package/dist/mcp-server/tools/fetchPubMedContent/logic.js +94 -202
- package/dist/mcp-server/tools/fetchPubMedContent/registration.js +43 -7
- package/dist/mcp-server/tools/generatePubMedChart/logic.d.ts +9 -28
- package/dist/mcp-server/tools/generatePubMedChart/logic.js +133 -192
- package/dist/mcp-server/tools/generatePubMedChart/registration.js +57 -13
- package/dist/mcp-server/tools/getPubMedArticleConnections/logic/citationFormatter.d.ts +1 -1
- package/dist/mcp-server/tools/getPubMedArticleConnections/logic/elinkHandler.d.ts +1 -1
- package/dist/mcp-server/tools/getPubMedArticleConnections/logic/index.d.ts +27 -4
- package/dist/mcp-server/tools/getPubMedArticleConnections/logic/index.js +50 -45
- package/dist/mcp-server/tools/getPubMedArticleConnections/logic/types.d.ts +1 -1
- package/dist/mcp-server/tools/getPubMedArticleConnections/registration.d.ts +0 -24
- package/dist/mcp-server/tools/getPubMedArticleConnections/registration.js +51 -45
- package/dist/mcp-server/tools/pubmedResearchAgent/logic.d.ts +2 -4
- package/dist/mcp-server/tools/pubmedResearchAgent/logic.js +7 -41
- package/dist/mcp-server/tools/pubmedResearchAgent/registration.js +49 -8
- package/dist/mcp-server/tools/searchPubMedArticles/logic.d.ts +12 -10
- package/dist/mcp-server/tools/searchPubMedArticles/logic.js +68 -126
- package/dist/mcp-server/tools/searchPubMedArticles/registration.js +46 -6
- package/dist/mcp-server/transports/{authentication → auth/core}/authContext.d.ts +2 -2
- package/dist/mcp-server/transports/{authentication → auth/core}/authContext.js +1 -1
- package/dist/mcp-server/transports/{authentication/types.d.ts → auth/core/authTypes.d.ts} +1 -1
- package/dist/mcp-server/transports/{authentication/types.js → auth/core/authTypes.js} +1 -1
- package/dist/mcp-server/transports/{authentication → auth/core}/authUtils.d.ts +1 -1
- package/dist/mcp-server/transports/{authentication → auth/core}/authUtils.js +3 -3
- package/dist/mcp-server/transports/auth/index.d.ts +10 -0
- package/dist/mcp-server/transports/auth/index.js +9 -0
- package/dist/mcp-server/transports/{authentication/authMiddleware.d.ts → auth/strategies/jwt/jwtMiddleware.d.ts} +4 -12
- package/dist/mcp-server/transports/{authentication/authMiddleware.js → auth/strategies/jwt/jwtMiddleware.js} +36 -43
- package/dist/mcp-server/transports/{authentication → auth/strategies/oauth}/oauthMiddleware.d.ts +2 -6
- package/dist/mcp-server/transports/{authentication → auth/strategies/oauth}/oauthMiddleware.js +33 -18
- package/dist/mcp-server/transports/httpErrorHandler.d.ts +26 -0
- package/dist/mcp-server/transports/httpErrorHandler.js +73 -0
- package/dist/mcp-server/transports/httpTransport.d.ts +11 -14
- package/dist/mcp-server/transports/httpTransport.js +91 -389
- package/package.json +13 -21
- package/dist/mcp-server/resources/echoResource/echoResourceLogic.d.ts +0 -79
- package/dist/mcp-server/resources/echoResource/echoResourceLogic.js +0 -82
- package/dist/mcp-server/resources/echoResource/index.d.ts +0 -13
- package/dist/mcp-server/resources/echoResource/index.js +0 -13
- package/dist/mcp-server/resources/echoResource/registration.d.ts +0 -30
- package/dist/mcp-server/resources/echoResource/registration.js +0 -168
- package/dist/mcp-server/tools/getPubMedArticleConnections/logic.d.ts +0 -6
- package/dist/mcp-server/tools/getPubMedArticleConnections/logic.js +0 -6
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Defines the core logic, schemas, and types for the `echo` resource.
|
|
3
|
-
* This module includes a Zod schema for query parameter validation, type definitions,
|
|
4
|
-
* and the main processing function that constructs the resource response.
|
|
5
|
-
* The echo resource is designed to return a message, typically extracted from the
|
|
6
|
-
* request URI's path or query parameters, along with a timestamp.
|
|
7
|
-
* @module src/mcp-server/resources/echoResource/echoResourceLogic
|
|
8
|
-
*/
|
|
9
|
-
import { z } from "zod";
|
|
10
|
-
import { type RequestContext } from "../../../utils/index.js";
|
|
11
|
-
/**
|
|
12
|
-
* Zod schema defining expected query parameters for the echo resource.
|
|
13
|
-
*
|
|
14
|
-
* This schema is intended for validating parameters passed via the URI's query string
|
|
15
|
-
* (e.g., `echo://some_message?message=override_from_query&anotherParam=value`).
|
|
16
|
-
* Path parameters, such as `{message}` in a template like `echo://{message}`,
|
|
17
|
-
* are typically defined in the `ResourceTemplate` (see `registration.ts`) and
|
|
18
|
-
* extracted by the MCP SDK from the URI path. The SDK merges these path
|
|
19
|
-
* parameters into the `params` object passed to the handler.
|
|
20
|
-
*
|
|
21
|
-
* If a path parameter and a query parameter share the same name (e.g., 'message'),
|
|
22
|
-
* the query parameter will take precedence over the path parameter. This schema
|
|
23
|
-
* defines `message` as an optional query parameter.
|
|
24
|
-
*/
|
|
25
|
-
export declare const EchoResourceQuerySchema: z.ZodObject<{
|
|
26
|
-
/**
|
|
27
|
-
* Optional message to be echoed back in the response.
|
|
28
|
-
* If the resource template also defines a 'message' path parameter,
|
|
29
|
-
* this query parameter will override the path parameter's value if both are present.
|
|
30
|
-
*/
|
|
31
|
-
message: z.ZodOptional<z.ZodString>;
|
|
32
|
-
}, "strip", z.ZodTypeAny, {
|
|
33
|
-
message?: string | undefined;
|
|
34
|
-
}, {
|
|
35
|
-
message?: string | undefined;
|
|
36
|
-
}>;
|
|
37
|
-
/**
|
|
38
|
-
* TypeScript type inferred from the {@link EchoResourceQuerySchema}.
|
|
39
|
-
* Represents the validated query parameters that might be passed to the echo resource.
|
|
40
|
-
*/
|
|
41
|
-
export type EchoResourceParams = z.infer<typeof EchoResourceQuerySchema>;
|
|
42
|
-
/**
|
|
43
|
-
* Defines the structure of the JSON payload returned by the `processEchoResource` function.
|
|
44
|
-
* This object is typically JSON-stringified by the resource handler before being sent
|
|
45
|
-
* as the resource content.
|
|
46
|
-
*
|
|
47
|
-
* @property message - The message that is being echoed. This could be from a path parameter,
|
|
48
|
-
* a query parameter (which takes precedence), or a default value.
|
|
49
|
-
* @property timestamp - An ISO 8601 timestamp indicating when the response was generated.
|
|
50
|
-
* @property requestUri - The full URI of the original resource request.
|
|
51
|
-
*/
|
|
52
|
-
export interface EchoResourceResponsePayload {
|
|
53
|
-
/** The message that is being echoed. */
|
|
54
|
-
message: string;
|
|
55
|
-
/** An ISO 8601 timestamp indicating when the response was generated. */
|
|
56
|
-
timestamp: string;
|
|
57
|
-
/** The full URI of the original resource request. */
|
|
58
|
-
requestUri: string;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Processes the core logic for an echo resource request.
|
|
62
|
-
* It constructs a response payload containing a message (derived from path or query parameters),
|
|
63
|
-
* the current timestamp, and the original request URI.
|
|
64
|
-
*
|
|
65
|
-
* The `params` argument is expected to contain validated query parameters. If the resource
|
|
66
|
-
* template (e.g., `echo://{message}`) includes path parameters, the MCP SDK extracts
|
|
67
|
-
* them and merges them into the `params` object. If a query parameter shares the same
|
|
68
|
-
* name as a path parameter, the query parameter's value takes precedence. This function
|
|
69
|
-
* assumes `params.message` will hold the definitive message.
|
|
70
|
-
*
|
|
71
|
-
* @param uri - The full URL object of the incoming resource request.
|
|
72
|
-
* @param params - The validated query parameters for the request.
|
|
73
|
-
* This object also includes path parameters merged by the SDK, with query parameters
|
|
74
|
-
* taking precedence in case of name conflicts.
|
|
75
|
-
* @param context - The request context, used for logging and tracing the operation.
|
|
76
|
-
* @returns The data payload for the response.
|
|
77
|
-
* This payload is typically JSON-stringified by the calling handler.
|
|
78
|
-
*/
|
|
79
|
-
export declare const processEchoResource: (uri: URL, params: EchoResourceParams, context: RequestContext) => EchoResourceResponsePayload;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Defines the core logic, schemas, and types for the `echo` resource.
|
|
3
|
-
* This module includes a Zod schema for query parameter validation, type definitions,
|
|
4
|
-
* and the main processing function that constructs the resource response.
|
|
5
|
-
* The echo resource is designed to return a message, typically extracted from the
|
|
6
|
-
* request URI's path or query parameters, along with a timestamp.
|
|
7
|
-
* @module src/mcp-server/resources/echoResource/echoResourceLogic
|
|
8
|
-
*/
|
|
9
|
-
import { z } from "zod";
|
|
10
|
-
import { logger } from "../../../utils/index.js";
|
|
11
|
-
/**
|
|
12
|
-
* Zod schema defining expected query parameters for the echo resource.
|
|
13
|
-
*
|
|
14
|
-
* This schema is intended for validating parameters passed via the URI's query string
|
|
15
|
-
* (e.g., `echo://some_message?message=override_from_query&anotherParam=value`).
|
|
16
|
-
* Path parameters, such as `{message}` in a template like `echo://{message}`,
|
|
17
|
-
* are typically defined in the `ResourceTemplate` (see `registration.ts`) and
|
|
18
|
-
* extracted by the MCP SDK from the URI path. The SDK merges these path
|
|
19
|
-
* parameters into the `params` object passed to the handler.
|
|
20
|
-
*
|
|
21
|
-
* If a path parameter and a query parameter share the same name (e.g., 'message'),
|
|
22
|
-
* the query parameter will take precedence over the path parameter. This schema
|
|
23
|
-
* defines `message` as an optional query parameter.
|
|
24
|
-
*/
|
|
25
|
-
export const EchoResourceQuerySchema = z.object({
|
|
26
|
-
/**
|
|
27
|
-
* Optional message to be echoed back in the response.
|
|
28
|
-
* If the resource template also defines a 'message' path parameter,
|
|
29
|
-
* this query parameter will override the path parameter's value if both are present.
|
|
30
|
-
*/
|
|
31
|
-
message: z
|
|
32
|
-
.string()
|
|
33
|
-
.optional()
|
|
34
|
-
.describe("Optional message to echo back in the response. If not provided, a default may be used or derived from the path."),
|
|
35
|
-
});
|
|
36
|
-
/**
|
|
37
|
-
* Processes the core logic for an echo resource request.
|
|
38
|
-
* It constructs a response payload containing a message (derived from path or query parameters),
|
|
39
|
-
* the current timestamp, and the original request URI.
|
|
40
|
-
*
|
|
41
|
-
* The `params` argument is expected to contain validated query parameters. If the resource
|
|
42
|
-
* template (e.g., `echo://{message}`) includes path parameters, the MCP SDK extracts
|
|
43
|
-
* them and merges them into the `params` object. If a query parameter shares the same
|
|
44
|
-
* name as a path parameter, the query parameter's value takes precedence. This function
|
|
45
|
-
* assumes `params.message` will hold the definitive message.
|
|
46
|
-
*
|
|
47
|
-
* @param uri - The full URL object of the incoming resource request.
|
|
48
|
-
* @param params - The validated query parameters for the request.
|
|
49
|
-
* This object also includes path parameters merged by the SDK, with query parameters
|
|
50
|
-
* taking precedence in case of name conflicts.
|
|
51
|
-
* @param context - The request context, used for logging and tracing the operation.
|
|
52
|
-
* @returns The data payload for the response.
|
|
53
|
-
* This payload is typically JSON-stringified by the calling handler.
|
|
54
|
-
*/
|
|
55
|
-
export const processEchoResource = (uri, params, context) => {
|
|
56
|
-
// The `params.message` can originate from a query parameter (validated by `EchoResourceQuerySchema`)
|
|
57
|
-
// or a path parameter (e.g., from a template like `echo://{message_from_path}`).
|
|
58
|
-
// The MCP SDK merges these, with query parameters taking precedence over path parameters if names conflict.
|
|
59
|
-
// The fallback "Default message..." is a safeguard if no message is provided via path or query.
|
|
60
|
-
const messageToEcho = params.message || `Default echo from ${uri.pathname}`;
|
|
61
|
-
logger.debug("Processing echo resource logic.", {
|
|
62
|
-
...context,
|
|
63
|
-
resourceUri: uri.href,
|
|
64
|
-
extractedMessage: messageToEcho,
|
|
65
|
-
queryParamMessage: params.message,
|
|
66
|
-
});
|
|
67
|
-
const responsePayload = {
|
|
68
|
-
message: messageToEcho,
|
|
69
|
-
timestamp: new Date().toISOString(),
|
|
70
|
-
requestUri: uri.href,
|
|
71
|
-
};
|
|
72
|
-
logger.debug("Echo resource processed successfully.", {
|
|
73
|
-
...context,
|
|
74
|
-
responsePayloadSummary: {
|
|
75
|
-
messageLength: responsePayload.message.length,
|
|
76
|
-
uriEchoed: responsePayload.requestUri.length > 50
|
|
77
|
-
? `${responsePayload.requestUri.substring(0, 47)}...`
|
|
78
|
-
: responsePayload.requestUri,
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
return responsePayload;
|
|
82
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Barrel file for the `echo` resource.
|
|
3
|
-
* This file serves as the public interface for the echo resource module,
|
|
4
|
-
* primarily exporting the `registerEchoResource` function. This function is
|
|
5
|
-
* responsible for registering the echo resource, including its templates and handler,
|
|
6
|
-
* with an MCP server instance. This makes the resource accessible to clients
|
|
7
|
-
* via defined URI patterns.
|
|
8
|
-
*
|
|
9
|
-
* Consuming modules should import from this barrel file to access
|
|
10
|
-
* the echo resource's registration capabilities.
|
|
11
|
-
* @module src/mcp-server/resources/echoResource/index
|
|
12
|
-
*/
|
|
13
|
-
export { registerEchoResource } from "./registration.js";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Barrel file for the `echo` resource.
|
|
3
|
-
* This file serves as the public interface for the echo resource module,
|
|
4
|
-
* primarily exporting the `registerEchoResource` function. This function is
|
|
5
|
-
* responsible for registering the echo resource, including its templates and handler,
|
|
6
|
-
* with an MCP server instance. This makes the resource accessible to clients
|
|
7
|
-
* via defined URI patterns.
|
|
8
|
-
*
|
|
9
|
-
* Consuming modules should import from this barrel file to access
|
|
10
|
-
* the echo resource's registration capabilities.
|
|
11
|
-
* @module src/mcp-server/resources/echoResource/index
|
|
12
|
-
*/
|
|
13
|
-
export { registerEchoResource } from "./registration.js";
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Handles the registration of the `echo` resource with an MCP server instance.
|
|
3
|
-
* This module defines the resource's template (URI structure), metadata (name, description, examples),
|
|
4
|
-
* and the asynchronous handler function that processes `resources/read` requests matching the template.
|
|
5
|
-
* It utilizes the MCP SDK's `server.resource()` method for registration and integrates
|
|
6
|
-
* robust error handling using the project's `ErrorHandler` utility.
|
|
7
|
-
* @module src/mcp-server/resources/echoResource/registration
|
|
8
|
-
*/
|
|
9
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
-
/**
|
|
11
|
-
* Registers the 'echo' resource and its handlers with the provided MCP server instance.
|
|
12
|
-
*
|
|
13
|
-
* This function defines:
|
|
14
|
-
* 1. The resource template (e.g., `echo://{message}`), which determines the URI structure.
|
|
15
|
-
* The `{message}` part is a path variable.
|
|
16
|
-
* 2. A `list` operation for the template to provide example/discoverable URIs.
|
|
17
|
-
* 3. Metadata for the resource, including its user-friendly name, description, MIME type,
|
|
18
|
-
* and example URIs.
|
|
19
|
-
* 4. The core asynchronous handler logic for `resources/read` requests that match the template.
|
|
20
|
-
* This handler processes the request and returns the resource content.
|
|
21
|
-
*
|
|
22
|
-
* Error handling is integrated throughout using `ErrorHandler.tryCatch` for robustness.
|
|
23
|
-
*
|
|
24
|
-
* @param server - The MCP server instance to register the resource with.
|
|
25
|
-
* @returns A promise that resolves when the resource registration is complete. It does not return a value upon successful completion.
|
|
26
|
-
* @throws {McpError} If the registration process fails critically, which might halt server startup.
|
|
27
|
-
* @see {@link EchoResourceParams} for the type of parameters passed to the handler.
|
|
28
|
-
* @see {@link processEchoResource} for the core resource logic.
|
|
29
|
-
*/
|
|
30
|
-
export declare const registerEchoResource: (server: McpServer) => Promise<void>;
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Handles the registration of the `echo` resource with an MCP server instance.
|
|
3
|
-
* This module defines the resource's template (URI structure), metadata (name, description, examples),
|
|
4
|
-
* and the asynchronous handler function that processes `resources/read` requests matching the template.
|
|
5
|
-
* It utilizes the MCP SDK's `server.resource()` method for registration and integrates
|
|
6
|
-
* robust error handling using the project's `ErrorHandler` utility.
|
|
7
|
-
* @module src/mcp-server/resources/echoResource/registration
|
|
8
|
-
*/
|
|
9
|
-
import { ResourceTemplate, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
-
import { BaseErrorCode, McpError } from "../../../types-global/errors.js";
|
|
11
|
-
import { ErrorHandler, logger, requestContextService, } from "../../../utils/index.js";
|
|
12
|
-
import { processEchoResource, } from "./echoResourceLogic.js";
|
|
13
|
-
/**
|
|
14
|
-
* Registers the 'echo' resource and its handlers with the provided MCP server instance.
|
|
15
|
-
*
|
|
16
|
-
* This function defines:
|
|
17
|
-
* 1. The resource template (e.g., `echo://{message}`), which determines the URI structure.
|
|
18
|
-
* The `{message}` part is a path variable.
|
|
19
|
-
* 2. A `list` operation for the template to provide example/discoverable URIs.
|
|
20
|
-
* 3. Metadata for the resource, including its user-friendly name, description, MIME type,
|
|
21
|
-
* and example URIs.
|
|
22
|
-
* 4. The core asynchronous handler logic for `resources/read` requests that match the template.
|
|
23
|
-
* This handler processes the request and returns the resource content.
|
|
24
|
-
*
|
|
25
|
-
* Error handling is integrated throughout using `ErrorHandler.tryCatch` for robustness.
|
|
26
|
-
*
|
|
27
|
-
* @param server - The MCP server instance to register the resource with.
|
|
28
|
-
* @returns A promise that resolves when the resource registration is complete. It does not return a value upon successful completion.
|
|
29
|
-
* @throws {McpError} If the registration process fails critically, which might halt server startup.
|
|
30
|
-
* @see {@link EchoResourceParams} for the type of parameters passed to the handler.
|
|
31
|
-
* @see {@link processEchoResource} for the core resource logic.
|
|
32
|
-
*/
|
|
33
|
-
export const registerEchoResource = async (server) => {
|
|
34
|
-
const resourceName = "echo-resource"; // Internal identifier for this resource registration.
|
|
35
|
-
const registrationContext = requestContextService.createRequestContext({
|
|
36
|
-
operation: "RegisterResource",
|
|
37
|
-
resourceName: resourceName,
|
|
38
|
-
moduleName: "EchoResourceRegistration",
|
|
39
|
-
});
|
|
40
|
-
logger.info(`Attempting to register resource: '${resourceName}'`, registrationContext);
|
|
41
|
-
await ErrorHandler.tryCatch(async () => {
|
|
42
|
-
// Define the resource template. This specifies the URI structure and supported operations.
|
|
43
|
-
// The URI `echo://{message}` uses RFC 6570 syntax, where `{message}` is a path variable.
|
|
44
|
-
const template = new ResourceTemplate("echo://{message}", {
|
|
45
|
-
/**
|
|
46
|
-
* Asynchronous handler for the `resources/list` operation associated with this template.
|
|
47
|
-
* It provides a list of example or discoverable resource URIs that match this template.
|
|
48
|
-
* This allows clients to discover how to interact with the echo resource.
|
|
49
|
-
*
|
|
50
|
-
* @returns A promise resolving to an object containing an array of resource descriptors.
|
|
51
|
-
*/
|
|
52
|
-
list: async () => {
|
|
53
|
-
const listContext = requestContextService.createRequestContext({
|
|
54
|
-
parentContext: registrationContext,
|
|
55
|
-
operation: "ListEchoResourceExamples",
|
|
56
|
-
});
|
|
57
|
-
logger.debug("Executing list operation for echo resource template.", listContext);
|
|
58
|
-
// Return a static list of example URIs.
|
|
59
|
-
return {
|
|
60
|
-
resources: [
|
|
61
|
-
{
|
|
62
|
-
uri: "echo://hello",
|
|
63
|
-
name: "Default Echo Message",
|
|
64
|
-
description: "A simple echo resource example using a default message.",
|
|
65
|
-
},
|
|
66
|
-
// Add more examples as needed
|
|
67
|
-
],
|
|
68
|
-
// nextCursor could be used here if the list were paginated.
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
// The `complete` operation (for URI completion suggestions) is optional and not implemented here.
|
|
72
|
-
});
|
|
73
|
-
logger.debug(`Resource template created for '${resourceName}': ${template.uriTemplate}`, registrationContext);
|
|
74
|
-
// Register the resource with the server.
|
|
75
|
-
// This involves providing the registration name, the template, metadata, and the handler for read operations.
|
|
76
|
-
server.resource(resourceName, template, {
|
|
77
|
-
name: "Echo Message Resource",
|
|
78
|
-
description: "A simple echo resource that returns a message, optionally specified in the URI path.",
|
|
79
|
-
mimeType: "application/json",
|
|
80
|
-
examples: [
|
|
81
|
-
{
|
|
82
|
-
name: "Basic echo",
|
|
83
|
-
uri: "echo://hello",
|
|
84
|
-
description: "Accesses the echo resource to echo the message 'hello'.",
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
name: "Custom echo",
|
|
88
|
-
uri: "echo://custom-message-here",
|
|
89
|
-
description: "Accesses the echo resource to echo 'custom-message-here'.",
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
},
|
|
93
|
-
/**
|
|
94
|
-
* Asynchronous handler for `resources/read` requests matching the `echo://{message}` template.
|
|
95
|
-
* This function is invoked by the MCP SDK when a client requests to read a resource
|
|
96
|
-
* whose URI matches the registered template.
|
|
97
|
-
*
|
|
98
|
-
* The SDK extracts path variables (like `{message}` from `echo://{message}`) from the URI.
|
|
99
|
-
* These path variables, along with any validated query parameters, are passed in the `params` object.
|
|
100
|
-
*
|
|
101
|
-
* @param uri - The full URL object of the resource being requested.
|
|
102
|
-
* @param params - An object containing parameters derived from the request.
|
|
103
|
-
* For this resource, it's expected to include `message` extracted from the URI
|
|
104
|
-
* path by the SDK. It conforms to {@link EchoResourceParams}.
|
|
105
|
-
* @returns A promise that resolves with the resource content, formatted as a `ReadResourceResult`.
|
|
106
|
-
* This includes the URI, Base64 encoded content blob, and MIME type.
|
|
107
|
-
* If an error is thrown from this handler, the SDK is responsible for catching it and
|
|
108
|
-
* formatting an error response.
|
|
109
|
-
*/
|
|
110
|
-
async (uri, params) => {
|
|
111
|
-
const handlerContext = requestContextService.createRequestContext({
|
|
112
|
-
parentContext: registrationContext,
|
|
113
|
-
operation: "HandleResourceRead",
|
|
114
|
-
resourceName: resourceName,
|
|
115
|
-
resourceUri: uri.href,
|
|
116
|
-
inputParamsSummary: params.message
|
|
117
|
-
? { messageLength: params.message.length }
|
|
118
|
-
: { noMessageParam: true },
|
|
119
|
-
});
|
|
120
|
-
logger.debug(`Handling read request for resource '${resourceName}', URI: ${uri.href}`, handlerContext);
|
|
121
|
-
return await ErrorHandler.tryCatch(async () => {
|
|
122
|
-
const responseData = processEchoResource(uri, params, handlerContext);
|
|
123
|
-
logger.debug(`'${resourceName}' (URI: ${uri.href}) processed successfully. Preparing content.`, handlerContext);
|
|
124
|
-
// Construct the `ReadResourceResult` as expected by the MCP SDK.
|
|
125
|
-
// The content (blob) must be Base64 encoded.
|
|
126
|
-
return {
|
|
127
|
-
contents: [
|
|
128
|
-
{
|
|
129
|
-
uri: uri.href,
|
|
130
|
-
blob: Buffer.from(JSON.stringify(responseData)).toString("base64"),
|
|
131
|
-
mimeType: "application/json",
|
|
132
|
-
},
|
|
133
|
-
],
|
|
134
|
-
};
|
|
135
|
-
}, {
|
|
136
|
-
operation: `ExecutingCoreLogicFor_${resourceName}_Read`,
|
|
137
|
-
context: handlerContext,
|
|
138
|
-
input: { uri: uri.href, params },
|
|
139
|
-
errorMapper: (error) => {
|
|
140
|
-
const baseErrorCode = error instanceof McpError
|
|
141
|
-
? error.code
|
|
142
|
-
: BaseErrorCode.INTERNAL_ERROR;
|
|
143
|
-
const errorMessage = `Error processing read request for resource '${uri.href}': ${error instanceof Error ? error.message : "An unknown error occurred"}`;
|
|
144
|
-
return new McpError(baseErrorCode, errorMessage, {
|
|
145
|
-
...handlerContext,
|
|
146
|
-
originalErrorName: error instanceof Error ? error.name : typeof error,
|
|
147
|
-
});
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
logger.info(`Resource '${resourceName}' (template: '${template.uriTemplate}') registered successfully.`, registrationContext);
|
|
152
|
-
}, {
|
|
153
|
-
operation: `RegisteringResource_${resourceName}`,
|
|
154
|
-
context: registrationContext,
|
|
155
|
-
errorCode: BaseErrorCode.INITIALIZATION_FAILED,
|
|
156
|
-
errorMapper: (error) => {
|
|
157
|
-
const errorMessage = `Failed to register resource '${resourceName}': ${error instanceof Error ? error.message : "An unknown error occurred during registration."}`;
|
|
158
|
-
const code = error instanceof McpError
|
|
159
|
-
? error.code
|
|
160
|
-
: BaseErrorCode.INITIALIZATION_FAILED;
|
|
161
|
-
return new McpError(code, errorMessage, {
|
|
162
|
-
...registrationContext,
|
|
163
|
-
originalErrorName: error instanceof Error ? error.name : typeof error,
|
|
164
|
-
});
|
|
165
|
-
},
|
|
166
|
-
critical: true,
|
|
167
|
-
});
|
|
168
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Core logic for the 'get_pubmed_article_connections' MCP tool.
|
|
3
|
-
* This file now re-exports the main handler from the './logic/index.js' module.
|
|
4
|
-
* @module src/mcp-server/tools/getPubMedArticleConnections/logic
|
|
5
|
-
*/
|
|
6
|
-
export { handleGetPubMedArticleConnections } from "./logic/index.js";
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Core logic for the 'get_pubmed_article_connections' MCP tool.
|
|
3
|
-
* This file now re-exports the main handler from the './logic/index.js' module.
|
|
4
|
-
* @module src/mcp-server/tools/getPubMedArticleConnections/logic
|
|
5
|
-
*/
|
|
6
|
-
export { handleGetPubMedArticleConnections } from "./logic/index.js";
|