Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export function MCPController(param?: MCPControllerParams) {
if (param?.version) {
MCPInfoUtil.setMCPVersion(param.version, constructor);
}
MCPInfoUtil.setMCPControllerParams(param, constructor);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export class MCPControllerMetaBuilder {
const version = MCPInfoUtil.getMCPVersion(this.clazz) || '1.0.0';
const needAcl = ControllerInfoUtil.hasControllerAcl(this.clazz);
const aclCode = ControllerInfoUtil.getControllerAcl(this.clazz);
const meta = MCPInfoUtil.getMCPControllerParams(this.clazz);
return new MCPControllerMeta(
clazzName, protoName, controllerName, name, version, tools, resources,
prompts, mcpMiddlewares, needAcl, aclCode,
prompts, mcpMiddlewares, needAcl, aclCode, meta,
);
}

Expand Down
5 changes: 4 additions & 1 deletion core/controller-decorator/src/model/MCPControllerMeta.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ControllerType } from '@eggjs/tegg-types';
import type { ControllerMetadata, MiddlewareFunc, EggPrototypeName } from '@eggjs/tegg-types';
import type { ControllerMetadata, MiddlewareFunc, EggPrototypeName, MCPControllerParams } from '@eggjs/tegg-types';
import { MCPToolMeta } from './MCPToolMeta';
import { MCPResourceMeta } from './MCPResourceMeta';
import { MCPPromptMeta } from './MCPPromptMeta';
Expand All @@ -18,6 +18,7 @@ export class MCPControllerMeta implements ControllerMetadata {
readonly tools: MCPToolMeta[];
readonly resources: MCPResourceMeta[];
readonly prompts: MCPPromptMeta[];
readonly timeout?: number;

get id() {
return `${this.name}:${1.0}`;
Expand All @@ -35,6 +36,7 @@ export class MCPControllerMeta implements ControllerMetadata {
middlewares: MiddlewareFunc[],
needAcl?: boolean,
aclCode?: string,
meta?: MCPControllerParams,
) {
this.protoName = protoName;
this.controllerName = controllerName;
Expand All @@ -48,6 +50,7 @@ export class MCPControllerMeta implements ControllerMetadata {
this.methods = [];
this.needAcl = !!needAcl;
this.aclCode = aclCode;
this.timeout = meta?.timeout;
}

getMethodMiddlewares(method: MCPPromptMeta | MCPToolMeta | MCPResourceMeta) {
Expand Down
10 changes: 10 additions & 0 deletions core/controller-decorator/src/util/MCPInfoUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
CONTROLLER_MCP_PROMPT_ARGS_INDEX,
CONTROLLER_MCP_EXTRA_INDEX,
CONTROLLER_MCP_PROMPT_PARAMS_MAP,
MCPControllerParams,
CONTROLLER_MCP_CONTROLLER_PARAMS_MAP,
} from '@eggjs/tegg-types';
import { MetadataUtil } from '@eggjs/core-decorator';
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
Expand Down Expand Up @@ -55,6 +57,14 @@ export class MCPInfoUtil {
return MetadataUtil.getMetaData(CONTROLLER_MCP_VERSION, clazz);
}

static setMCPControllerParams(params: MCPControllerParams | undefined, clazz: EggProtoImplClass) {
MetadataUtil.defineMetaData(CONTROLLER_MCP_CONTROLLER_PARAMS_MAP, params, clazz);
}

static getMCPControllerParams(clazz: EggProtoImplClass): MCPControllerParams | undefined {
return MetadataUtil.getMetaData(CONTROLLER_MCP_CONTROLLER_PARAMS_MAP, clazz);
}

static setMCPResource(clazz: EggProtoImplClass, methodName: string) {
const methodMap: MCPMethodMap = MetadataUtil.initOwnMapMetaData(CONTROLLER_MCP_RESOURCE_MAP, clazz, new Map());
methodMap.set(methodName, true);
Expand Down
1 change: 1 addition & 0 deletions core/controller-decorator/test/MCPMeta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ describe('test/MCPMeta.test.ts', () => {
assert(fooControllerMetaData.resources[0].template instanceof ResourceTemplate);
assert(fooControllerMetaData.tools[0].detail?.argsSchema === ToolType);
assert(fooControllerMetaData.prompts[0].detail?.argsSchema === PromptType);
assert(fooControllerMetaData.timeout === 60000);
});
});
1 change: 1 addition & 0 deletions core/controller-decorator/test/fixtures/MCPController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const ToolType = {

@MCPController({
name: "HelloChairMCP",
timeout: 60000,
})
export class MCPFooController {

Expand Down
1 change: 1 addition & 0 deletions core/types/controller-decorator/MCPController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface MCPControllerParams {
controllerName?: string;
name?: string;
version?: string;
timeout?: number;
}
1 change: 1 addition & 0 deletions core/types/controller-decorator/MCPPromptParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export type MCPPromptResponse = GetPromptResult;
export interface MCPPromptParams {
name?: string;
description?: string;
timeout?: number;
}
2 changes: 2 additions & 0 deletions core/types/controller-decorator/MCPResourceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ export interface MCPResourceUriParams {
name?: string;
uri: string;
metadata?: ResourceMetadata;
timeout?: number;
}

export interface MCPResourceTemplateParams {
name?: string;
template: ConstructorParameters<typeof ResourceTemplate>;
metadata?: ResourceMetadata;
timeout?: number;
}

export type ResourceExtra = Parameters<Parameters<McpServer['resource']>['3']>['2'];
Expand Down
1 change: 1 addition & 0 deletions core/types/controller-decorator/MCPToolParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export type MCPToolResponse = CallToolResult;
export interface MCPToolParams {
name?: string;
description?: string;
timeout?: number;
}

1 change: 1 addition & 0 deletions core/types/controller-decorator/MetadataKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const METHOD_TIMEOUT_METADATA = Symbol.for('EggPrototype#method#timeout')

export const CONTROLLER_MCP_NAME = Symbol.for('EggPrototype#controller#mcp#name');
export const CONTROLLER_MCP_VERSION = Symbol.for('EggPrototype#controller#mcp#version');
export const CONTROLLER_MCP_CONTROLLER_PARAMS_MAP = Symbol.for('EggPrototype#controller#mcp#controller#params');
export const CONTROLLER_MCP_RESOURCE_MAP = Symbol.for('EggPrototype#controller#mcp#resource');
export const CONTROLLER_MCP_RESOURCE_PARAMS_MAP = Symbol.for('EggPrototype#controller#mcp#resource#params');
export const CONTROLLER_MCP_TOOL_MAP = Symbol.for('EggPrototype#controller#mcp#tool');
Expand Down
Loading