File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import fs from 'fs' ;
44import path from 'path' ;
55import { fileURLToPath } from 'url' ;
6- import { execSync } from 'child_process' ;
76
87// Get the directory where the source files are stored
98const __filename = fileURLToPath ( import . meta. url ) ;
@@ -171,7 +170,7 @@ function createProjectPackageJson() {
171170 "typescript" : "^5.8.2"
172171 } ,
173172 dependencies : {
174- "@modelcontextprotocol/sdk " : "^1.7 .0" ,
173+ "fastmcp " : "^1.21 .0" ,
175174 "cors" : "^2.8.5" ,
176175 "express" : "^4.21.2" ,
177176 "zod" : "^3.24.2"
Original file line number Diff line number Diff line change 6969 "typescript" : " ^5.8.2"
7070 },
7171 "dependencies" : {
72- "@modelcontextprotocol/sdk" : " ^1.7.0" ,
7372 "cors" : " ^2.8.5" ,
7473 "express" : " ^4.21.2" ,
74+ "fastmcp" : " ^1.21.0" ,
7575 "zod" : " ^3.24.2"
7676 },
7777 "engines" : {
Original file line number Diff line number Diff line change 1- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js " ;
1+ import { FastMCP } from "fastmcp " ;
22import { z } from "zod" ;
33
44/**
55 * Register all prompts with the MCP server
6- * @param server The MCP server instance
6+ * @param server The FastMCP server instance
77 */
8- export function registerPrompts ( server : McpServer ) {
8+ export function registerPrompts ( server : FastMCP ) {
99 // Example prompt
10- server . prompt (
11- "greeting" ,
12- "A simple greeting prompt" ,
13- {
14- name : z . string ( ) . describe ( "Name to greet" )
15- } ,
16- ( params : { name : string } ) => ( {
17- messages : [ {
18- role : "user" ,
19- content : {
20- type : "text" ,
21- text : `Hello, ${ params . name } ! How can I help you today?`
22- }
23- } ]
24- } )
25- ) ;
10+ server . addPrompt ( {
11+ name : "greeting" ,
12+ description : "A simple greeting prompt" ,
13+ arguments : [
14+ {
15+ name : "name" ,
16+ description : "Name to greet" ,
17+ required : true ,
18+ } ,
19+ ] ,
20+ load : async ( { name } ) => {
21+ return `Hello, ${ name } ! How can I help you today?` ;
22+ }
23+ } ) ;
2624}
Original file line number Diff line number Diff line change 1- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js " ;
1+ import { FastMCP } from "fastmcp " ;
22import * as services from "./services/index.js" ;
33
44/**
55 * Register all resources with the MCP server
6- * @param server The MCP server instance
6+ * @param server The FastMCP server instance
77 */
8- export function registerResources ( server : McpServer ) {
8+ export function registerResources ( server : FastMCP ) {
99 // Example resource
10- server . resource (
11- "example_resource" ,
12- "example://{id}" ,
13- async ( uri : URL ) => {
14- const id = uri . pathname . split ( '/' ) . pop ( ) ;
10+ server . addResourceTemplate ( {
11+ uriTemplate : "example://{id}" ,
12+ name : "Example Resource" ,
13+ mimeType : "text/plain" ,
14+ arguments : [
15+ {
16+ name : "id" ,
17+ description : "Resource ID" ,
18+ required : true ,
19+ } ,
20+ ] ,
21+ async load ( { id } ) {
1522 return {
16- contents : [ {
17- uri : uri . toString ( ) ,
18- text : `This is an example resource with ID: ${ id } `
19- } ]
23+ text : `This is an example resource with ID: ${ id } `
2024 } ;
2125 }
22- ) ;
26+ } ) ;
2327}
Original file line number Diff line number Diff line change 1- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js " ;
1+ import { FastMCP } from "fastmcp " ;
22import { z } from "zod" ;
33import * as services from "./services/index.js" ;
44
55/**
66 * Register all tools with the MCP server
77 *
8- * @param server The MCP server instance
8+ * @param server The FastMCP server instance
99 */
10- export function registerTools ( server : McpServer ) {
10+ export function registerTools ( server : FastMCP ) {
1111 // Greeting tool
12- server . tool (
13- "hello_world" ,
14- "A simple hello world tool" ,
15- {
12+ server . addTool ( {
13+ name : "hello_world" ,
14+ description : "A simple hello world tool" ,
15+ parameters : z . object ( {
1616 name : z . string ( ) . describe ( "Name to greet" )
17- } ,
18- async ( params : { name : string } ) => {
17+ } ) ,
18+ execute : async ( params ) => {
1919 const greeting = services . GreetingService . generateGreeting ( params . name ) ;
20- return {
21- content : [
22- {
23- type : "text" ,
24- text : greeting
25- }
26- ]
27- } ;
20+ return greeting ;
2821 }
29- ) ;
22+ } ) ;
3023
3124 // Farewell tool
32- server . tool (
33- "goodbye" ,
34- "A simple goodbye tool" ,
35- {
25+ server . addTool ( {
26+ name : "goodbye" ,
27+ description : "A simple goodbye tool" ,
28+ parameters : z . object ( {
3629 name : z . string ( ) . describe ( "Name to bid farewell to" )
37- } ,
38- async ( params : { name : string } ) => {
30+ } ) ,
31+ execute : async ( params ) => {
3932 const farewell = services . GreetingService . generateFarewell ( params . name ) ;
40- return {
41- content : [
42- {
43- type : "text" ,
44- text : farewell
45- }
46- ]
47- } ;
33+ return farewell ;
4834 }
49- ) ;
35+ } ) ;
5036}
Original file line number Diff line number Diff line change 1- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js " ;
1+ import { FastMCP } from "fastmcp " ;
22import startServer from "./server/server.js" ;
33
44// Start the server
55async function main ( ) {
66 try {
77 const server = await startServer ( ) ;
8- const transport = new StdioServerTransport ( ) ;
9- await server . connect ( transport ) ;
8+
9+ server . start ( {
10+ transportType : "stdio" ,
11+ } ) ;
12+
1013 console . error ( "MCP Server running on stdio" ) ;
1114 } catch ( error ) {
1215 console . error ( "Error starting MCP server:" , error ) ;
You can’t perform that action at this time.
0 commit comments