Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion core/controller-decorator/src/model/MCPToolMeta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MethodMeta, MiddlewareFunc } from '@eggjs/tegg-types';
import type { MCPToolParams, MethodMeta, MiddlewareFunc } from '@eggjs/tegg-types';
import { ToolArgsSchemaDetail } from '../../src/util/MCPInfoUtil';


Expand All @@ -8,6 +8,7 @@ export class MCPToolMeta implements MethodMeta {
readonly aclCode?: string;
readonly mcpName?: string;
readonly description?: string;
readonly meta?: MCPToolParams['meta'];
readonly detail?: ToolArgsSchemaDetail;
readonly middlewares: readonly MiddlewareFunc[];
readonly extra?: number;
Expand All @@ -20,13 +21,15 @@ export class MCPToolMeta implements MethodMeta {
needAcl?: boolean;
aclCode?: string,
description?: string;
meta?: MCPToolParams['meta'];
mcpName?: string;
detail?: ToolArgsSchemaDetail;
extra?: number;
}) {
this.name = opt.name;
this.needAcl = !!opt.needAcl;
this.description = opt.description;
this.meta = opt.meta;
this.mcpName = opt.mcpName;
this.middlewares = opt.middlewares;
this.aclCode = opt.aclCode;
Expand Down
6 changes: 6 additions & 0 deletions core/controller-decorator/test/MCPMeta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ describe('test/MCPMeta.test.ts', () => {
assert(fooControllerMetaData.className === 'MCPFooController');
assert(fooControllerMetaData.prompts[0].name === 'foo');
assert(fooControllerMetaData.tools[0].name === 'bar');
assert.deepStrictEqual(fooControllerMetaData.tools[0].meta, {
ui: {
resourceUri: 'ui://test/tool',
visibility: [ 'model', 'app' ],
},
});
assert(fooControllerMetaData.resources[0].name === 'car');
assert(fooControllerMetaData.resources[0].template instanceof ResourceTemplate);
assert.strictEqual(fooControllerMetaData.tools[0].detail?.argsSchema as unknown, ToolType);
Expand Down
9 changes: 8 additions & 1 deletion core/controller-decorator/test/fixtures/MCPController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ export class MCPFooController {
};
}

@MCPTool()
@MCPTool({
meta: {
ui: {
resourceUri: 'ui://test/tool',
visibility: [ 'model', 'app' ],
},
},
})
async bar(@ToolArgsSchema(ToolType as any) args: ToolArgs<any>, @Context() ctx: object): Promise<MCPToolResponse> {
void ctx;
return {
Expand Down
13 changes: 12 additions & 1 deletion core/types/controller-decorator/MCPToolParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@ export type ToolExtra = Parameters<Parameters<McpServer['tool']>['4']>['1'];

export type MCPToolResponse = CallToolResult;

export type MCPToolVisibility = 'model' | 'app';

export interface MCPToolUIMeta {
resourceUri?: string;
visibility?: MCPToolVisibility[];
}

export type MCPToolRegistrationMeta = {
ui: MCPToolUIMeta;
};
Comment thread
lighte-chen marked this conversation as resolved.

export interface MCPToolParams {
name?: string;
description?: string;
timeout?: number;
meta?: MCPToolRegistrationMeta;
}

1 change: 1 addition & 0 deletions plugin/controller/lib/impl/mcp/MCPServerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export class MCPServerHelper {
this.server.registerTool(name, {
description,
inputSchema: schema,
_meta: toolMeta.meta,
// TODO: outputSchema
}, handler);
}
Expand Down
14 changes: 13 additions & 1 deletion plugin/controller/test/mcp/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ describe('plugin/controller/test/mcp/mcp.test.ts', () => {
name: 'testTool',
needAcl: false,
middlewares: [],
meta: {
ui: {
resourceUri: 'ui://test/tool',
visibility: [ 'model', 'app' ],
},
},
contextParamIndex: 1,
detail: {
argsSchema: ToolType,
Expand Down Expand Up @@ -128,10 +134,16 @@ describe('plugin/controller/test/mcp/mcp.test.ts', () => {
]);
const tools = await client.listTools();

assert.deepEqual(tools.tools.map(tool => ({ name: tool.name, description: tool.description })), [
assert.deepEqual(tools.tools.map(tool => ({ name: tool.name, description: tool.description, _meta: tool._meta })), [
{
description: undefined,
name: 'testTool',
_meta: {
ui: {
resourceUri: 'ui://test/tool',
visibility: [ 'model', 'app' ],
},
},
},
]);

Expand Down
1 change: 1 addition & 0 deletions standalone/service-worker/src/mcp/MCPServerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
ToolCallback,
PromptCallback,
} from '@modelcontextprotocol/sdk/server/mcp.js';
import { CONTROLLER_META_DATA } from '@eggjs/tegg';

Check warning on line 7 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (18)

'/Users/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

Check warning on line 7 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (16)

'/Users/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

Check warning on line 7 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (16)

'/home/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

Check warning on line 7 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (20)

'/Users/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

Check warning on line 7 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (20)

'/home/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

Check warning on line 7 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (18)

'/home/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times
import type { EggObject, EggObjectName, EggPrototype } from '@eggjs/tegg-types';
import { MCPControllerMeta, MCPPromptMeta, MCPResourceMeta, MCPToolMeta } from '@eggjs/tegg';

Check warning on line 9 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (18)

'/Users/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

Check warning on line 9 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (16)

'/Users/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

Check warning on line 9 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (16)

'/home/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

Check warning on line 9 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-macos (20)

'/Users/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

Check warning on line 9 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (20)

'/home/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

Check warning on line 9 in standalone/service-worker/src/mcp/MCPServerHelper.ts

View workflow job for this annotation

GitHub Actions / Runner-ubuntu (18)

'/home/runner/work/tegg/tegg/node_modules/@eggjs/tegg/index.ts' imported multiple times

export interface MCPServerHelperOptions {
name: string;
Expand Down Expand Up @@ -125,6 +125,7 @@
this.server.registerTool(name, {
description,
inputSchema: schema,
_meta: toolMeta.meta,
}, handler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ const AddArgs = {
@Middleware(McpTestAdvice)
@MCPController({ name: 'test-server', version: '1.0.0' })
export class MCPTestController {
@MCPTool({ description: 'Echo the input message' })
@MCPTool({
description: 'Echo the input message',
meta: {
ui: {
resourceUri: 'ui://test/echo',
visibility: [ 'model' ],
},
},
})
async echo(@ToolArgsSchema(EchoArgs) args: ToolArgs<typeof EchoArgs>): Promise<MCPToolResponse> {
return {
content: [{ type: 'text', text: args.message }],
Expand Down
6 changes: 6 additions & 0 deletions standalone/service-worker/test/mcp/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ describe('standalone/service-worker/test/mcp/mcp.test.ts', () => {

const echoTool = result.tools.find(t => t.name === 'echo');
assert.strictEqual(echoTool?.description, 'Echo the input message');
assert.deepStrictEqual(echoTool?._meta, {
ui: {
resourceUri: 'ui://test/echo',
visibility: [ 'model' ],
},
});

const addTool = result.tools.find(t => t.name === 'add');
assert.strictEqual(addTool?.description, 'Add two numbers');
Expand Down
Loading