@@ -5,9 +5,12 @@ import {
55 CallToolRequestSchema ,
66 ErrorCode ,
77 ListToolsRequestSchema ,
8+ ListResourcesRequestSchema ,
9+ ReadResourceRequestSchema ,
810 McpError ,
911} from '@modelcontextprotocol/sdk/types.js' ;
1012import axios , { AxiosInstance , AxiosRequestConfig , Method } from 'axios' ;
13+ import { VERSION , PACKAGE_NAME , SERVER_NAME } from './version.js' ;
1114
1215if ( ! process . env . REST_BASE_URL ) {
1316 throw new Error ( 'REST_BASE_URL environment variable is required' ) ;
@@ -49,12 +52,13 @@ class RestTester {
4952 private async setupServer ( ) {
5053 this . server = new Server (
5154 {
52- name : 'rest-tester' ,
53- version : '0.1.0' ,
55+ name : SERVER_NAME ,
56+ version : VERSION ,
5457 } ,
5558 {
5659 capabilities : {
5760 tools : { } ,
61+ resources : { } ,
5862 } ,
5963 }
6064 ) ;
@@ -69,6 +73,7 @@ class RestTester {
6973 } ) ;
7074
7175 this . setupToolHandlers ( ) ;
76+ this . setupResourceHandlers ( ) ;
7277
7378 this . server . onerror = ( error ) => console . error ( '[MCP Error]' , error ) ;
7479 process . on ( 'SIGINT' , async ( ) => {
@@ -77,6 +82,65 @@ class RestTester {
7782 } ) ;
7883 }
7984
85+ private setupResourceHandlers ( ) {
86+ this . server . setRequestHandler ( ListResourcesRequestSchema , async ( ) => ( {
87+ resources : [
88+ {
89+ uri : `${ SERVER_NAME } ://examples` ,
90+ name : 'REST API Usage Examples' ,
91+ description : 'Detailed examples of using the REST API testing tool' ,
92+ mimeType : 'text/markdown'
93+ } ,
94+ {
95+ uri : `${ SERVER_NAME } ://response-format` ,
96+ name : 'Response Format Documentation' ,
97+ description : 'Documentation of the response format and structure' ,
98+ mimeType : 'text/markdown'
99+ }
100+ ]
101+ } ) ) ;
102+
103+ this . server . setRequestHandler ( ReadResourceRequestSchema , async ( request ) => {
104+ const uriPattern = new RegExp ( `^${ SERVER_NAME } ://(.+)$` ) ;
105+ const match = request . params . uri . match ( uriPattern ) ;
106+
107+ if ( ! match ) {
108+ throw new McpError (
109+ ErrorCode . InvalidRequest ,
110+ `Invalid resource URI format: ${ request . params . uri } `
111+ ) ;
112+ }
113+
114+ const resource = match [ 1 ] ;
115+ const fs = await import ( 'fs' ) ;
116+ const path = await import ( 'path' ) ;
117+
118+ try {
119+ const url = await import ( 'url' ) ;
120+ const __filename = url . fileURLToPath ( import . meta. url ) ;
121+ const __dirname = path . dirname ( __filename ) ;
122+
123+ // In the built app, resources are in build/resources
124+ // In development, they're in src/resources
125+ const resourcePath = path . join ( __dirname , 'resources' , `${ resource } .md` ) ;
126+ const content = await fs . promises . readFile ( resourcePath , 'utf8' ) ;
127+
128+ return {
129+ contents : [ {
130+ uri : request . params . uri ,
131+ mimeType : 'text/markdown' ,
132+ text : content
133+ } ]
134+ } ;
135+ } catch ( error ) {
136+ throw new McpError (
137+ ErrorCode . InvalidRequest ,
138+ `Resource not found: ${ resource } `
139+ ) ;
140+ }
141+ } ) ;
142+ }
143+
80144 private setupToolHandlers ( ) {
81145 this . server . setRequestHandler ( ListToolsRequestSchema , async ( ) => ( {
82146 tools : [
0 commit comments