Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit 74faca6

Browse files
committed
revert: type annotations
1 parent 38c10ee commit 74faca6

2 files changed

Lines changed: 43 additions & 19 deletions

File tree

packages/mcp-use/src/server/mcp-server.ts

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
TemplateDefinition,
66
ToolDefinition,
77
} from './types.js'
8-
import { McpServer as OfficialMcpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
8+
import { McpServer as OfficialMcpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
99
import { z } from 'zod'
1010
import express, { type Express } from 'express'
1111
import { existsSync, readdirSync } from 'node:fs'
@@ -61,7 +61,15 @@ export class McpServer {
6161
description: definition.description,
6262
mimeType: definition.mimeType,
6363
},
64-
definition.fn,
64+
async () => ({
65+
contents: [
66+
{
67+
uri: definition.uri,
68+
mimeType: definition.mimeType || 'text/plain',
69+
text: await definition.fn(),
70+
},
71+
],
72+
}),
6573
)
6674
return this
6775
}
@@ -70,16 +78,24 @@ export class McpServer {
7078
* Define a resource template with parameterized URIs
7179
*/
7280
template(definition: TemplateDefinition): this {
73-
const template = new ResourceTemplate(definition.uriTemplate, { list: undefined })
74-
this.server.resource(
75-
definition.name || definition.uriTemplate,
76-
template,
77-
{
78-
name: definition.name,
79-
description: definition.description,
80-
mimeType: definition.mimeType,
81+
// For templates, we'll register them as tools that return resource content
82+
const toolName = `template_${definition.uriTemplate.replace(/[^a-z0-9]/gi, '_')}`
83+
84+
this.server.tool(
85+
toolName,
86+
definition.description || 'Resource Template',
87+
this.createInputSchema(definition.uriTemplate),
88+
async (params: any) => {
89+
const content = await definition.fn(params as Record<string, string>)
90+
return {
91+
content: [
92+
{
93+
type: 'text',
94+
text: content,
95+
},
96+
],
97+
}
8198
},
82-
definition.fn,
8399
)
84100
return this
85101
}
@@ -114,7 +130,17 @@ export class McpServer {
114130
argsSchema,
115131
async (params: any) => {
116132
const result = await definition.fn(params)
117-
return result
133+
return {
134+
messages: [
135+
{
136+
role: 'user',
137+
content: {
138+
type: 'text',
139+
text: result,
140+
},
141+
},
142+
],
143+
}
118144
},
119145
)
120146
return this

packages/mcp-use/src/server/types.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CallToolResult, GetPromptResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js'
1+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js'
22
export interface ServerConfig {
33
name: string
44
version: string
@@ -43,9 +43,7 @@ export interface PromptDefinition {
4343
fn: PromptHandler
4444
}
4545

46-
import type { Variables } from '@modelcontextprotocol/sdk/shared/uriTemplate.js'
47-
48-
export type ResourceHandler = () => Promise<ReadResourceResult>
49-
export type TemplateHandler = (uri: URL, variables: Variables) => Promise<ReadResourceResult>
50-
export type ToolHandler<TInput = Record<string, any>> = (params: TInput) => Promise<CallToolResult>
51-
export type PromptHandler<TInput = Record<string, any>> = (params: TInput) => Promise<GetPromptResult>
46+
export type ResourceHandler = () => Promise<string>
47+
export type TemplateHandler = (params: Record<string, string>) => Promise<string>
48+
export type ToolHandler = (params: Record<string, any>) => Promise<CallToolResult>
49+
export type PromptHandler = (params: Record<string, any>) => Promise<string>

0 commit comments

Comments
 (0)