@@ -28,8 +28,11 @@ export default function (server: McpServer, context: Context, options: Options)
2828 // @ts -expect-error -- Generic type handling
2929 return server . registerTool ( name , config , async ( ...args ) => {
3030 try {
31- const res = await Promise . resolve ( callback ( ...args ) ) ;
32- return _processResponse ( res , options ) ;
31+ // @ts -expect-error -- Generic type handling
32+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- Generic type handling
33+ const toolResult = callback ( ...args ) ;
34+ const response = await Promise . resolve ( toolResult ) ;
35+ return _processResponse ( response , options ) ;
3336 } catch ( error ) {
3437 handleError ( error ) ;
3538 }
@@ -57,14 +60,16 @@ export function _processResponse({content, structuredContent}: CallToolResult, o
5760 if ( ! options . useResourcesInResponse ) {
5861 content = content . map ( ( item ) => {
5962 if ( item . type === "resource" ) {
60- let text = item . resource . text as string ;
61- if ( item . resource . title && typeof item . resource . title === "string" ) {
62- text = `# ${ item . resource . title } \n\n${ text } ` ;
63+ if ( "text" in item . resource && typeof item . resource . text === "string" ) {
64+ return {
65+ type : "text" as const ,
66+ text : item . resource . text ,
67+ } ;
68+ } else {
69+ throw new Error (
70+ `Unable to convert resource without text content to text content: ${ JSON . stringify ( item ) } `
71+ ) ;
6372 }
64- return {
65- type : "text" ,
66- text,
67- } ;
6873 }
6974 return item ;
7075 } ) ;
0 commit comments