@@ -2,7 +2,6 @@ import type {
22 PromptDefinition ,
33 ResourceDefinition ,
44 ServerConfig ,
5- TemplateDefinition ,
65 ToolDefinition ,
76} from './types.js'
87import { McpServer as OfficialMcpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
@@ -52,69 +51,46 @@ export class McpServer {
5251 }
5352
5453 /**
55- * Define a resource that can be accessed by clients
54+ * Define a static resource that can be accessed by clients
5655 */
57- resource ( definition : ResourceDefinition ) : this {
56+ resource ( resourceDefinition : ResourceDefinition ) : this {
5857 this . server . resource (
59- definition . name || definition . uri ,
60- definition . uri ,
61- {
62- name : definition . name ,
63- description : definition . description ,
64- mimeType : definition . mimeType ,
58+ resourceDefinition . name ,
59+ resourceDefinition . uri ,
60+ resourceDefinition . resource ,
61+ async ( ) => {
62+ return await resourceDefinition . fn ( )
6563 } ,
66- async ( ) => ( {
67- contents : [
68- {
69- uri : definition . uri ,
70- mimeType : definition . mimeType || 'text/plain' ,
71- text : await definition . fn ( ) ,
72- } ,
73- ] ,
74- } ) ,
7564 )
7665 return this
7766 }
7867
7968 /**
80- * Define a resource template with parameterized URIs
69+ * Define a dynamic resource template with parameters
8170 */
82- template ( definition : TemplateDefinition ) : this {
83- // For templates, we'll register them as tools that return resource content
84- const toolName = `template_${ definition . uriTemplate . replace ( / [ ^ a - z 0 - 9 ] / gi, '_' ) } `
85-
86- this . server . tool (
87- toolName ,
88- definition . description || 'Resource Template' ,
89- this . createInputSchema ( definition . uriTemplate ) ,
90- async ( params : any ) => {
91- const content = await definition . fn ( params as Record < string , string > )
92- return {
93- content : [
94- {
95- type : 'text' ,
96- text : content ,
97- } ,
98- ] ,
99- }
100- } ,
101- )
102- return this
103- }
71+ // TODO implement, for some freaky reason this give errors
72+ // resourceTemplate(resourceTemplateDefinition: ResourceTemplateDefinition): this {
73+ // this.server.resource(
74+ // resourceTemplateDefinition.name,
75+ // resourceTemplateDefinition.resourceTemplate,
76+ // async (uri, params) => {
77+ // return await resourceTemplateDefinition.fn(uri, params)
78+ // },
79+ // )
80+ // return this
81+ // }
10482
10583 /**
10684 * Define a tool that can be called by clients
10785 */
108- tool ( definition : ToolDefinition ) : this {
109- const inputSchema = this . createToolInputSchema ( definition . inputs || [ ] )
110-
86+ tool ( toolDefinition : ToolDefinition ) : this {
87+ const inputSchema = this . createToolInputSchema ( toolDefinition . inputs || [ ] )
11188 this . server . tool (
112- definition . name ,
113- definition . description || definition . name ,
89+ toolDefinition . name ,
90+ toolDefinition . description ?? "" ,
11491 inputSchema ,
11592 async ( params : any ) => {
116- const result = await definition . fn ( params )
117- return result
93+ return await toolDefinition . fn ( params )
11894 } ,
11995 )
12096 return this
@@ -123,26 +99,14 @@ export class McpServer {
12399 /**
124100 * Define a prompt template
125101 */
126- prompt ( definition : PromptDefinition ) : this {
127- const argsSchema = this . createPromptArgsSchema ( definition . args || [ ] )
128-
102+ prompt ( promptDefinition : PromptDefinition ) : this {
103+ const argsSchema = this . createPromptArgsSchema ( promptDefinition . args || [ ] )
129104 this . server . prompt (
130- definition . name ,
131- definition . description || definition . name ,
105+ promptDefinition . name ,
106+ promptDefinition . description ?? "" ,
132107 argsSchema ,
133108 async ( params : any ) => {
134- const result = await definition . fn ( params )
135- return {
136- messages : [
137- {
138- role : 'user' ,
139- content : {
140- type : 'text' ,
141- text : result ,
142- } ,
143- } ,
144- ] ,
145- }
109+ return await promptDefinition . fn ( params )
146110 } ,
147111 )
148112 return this
0 commit comments