77package modelengine .fel .tool .mcp .server ;
88
99import io .modelcontextprotocol .server .McpServerFeatures ;
10- import io .modelcontextprotocol .server .McpSyncServerExchange ;
1110import io .modelcontextprotocol .spec .McpSchema ;
1211import modelengine .fel .tool .mcp .entity .ServerSchema ;
1312import modelengine .fel .tool .mcp .entity .Tool ;
2322import java .util .List ;
2423import java .util .Map ;
2524import java .util .concurrent .ConcurrentHashMap ;
26- import java .util .function .BiFunction ;
2725
2826import static modelengine .fel .tool .info .schema .PluginSchema .TYPE ;
2927import static modelengine .fel .tool .info .schema .ToolsSchema .PROPERTIES ;
@@ -59,8 +57,10 @@ public DefaultMcpServer(ToolExecuteService toolExecuteService, McpSyncServer mcp
5957
6058 @ Override
6159 public ServerSchema getSchema () {
62- McpSchema .Implementation info = this .mcpSyncServer .getServerInfo ();
63- McpSchema .ServerCapabilities capabilities = this .mcpSyncServer .getServerCapabilities ();
60+ ServerSchema .Info info = new ServerSchema .Info ("FIT Store MCP Server" , "3.6.0-SNAPSHOT" );
61+ ServerSchema .Capabilities .Logging logging = new ServerSchema .Capabilities .Logging ();
62+ ServerSchema .Capabilities .Tools tools = new ServerSchema .Capabilities .Tools (true );
63+ ServerSchema .Capabilities capabilities = new ServerSchema .Capabilities (logging , tools );
6464 return new ServerSchema ("2025-06-18" , capabilities , info );
6565 }
6666
@@ -77,8 +77,7 @@ public void registerToolsChangedObserver(ToolsChangedObserver observer) {
7777 }
7878
7979 @ Override
80- public void addTool (String name , String description , McpSchema .JsonSchema inputSchema ,
81- BiFunction <McpSyncServerExchange , McpSchema .CallToolRequest , McpSchema .CallToolResult > callHandler ) {
80+ public void onToolAdded (String name , String description , Map <String , Object > parameters ) {
8281 if (StringUtils .isBlank (name )) {
8382 log .warn ("Tool addition is ignored: tool name is blank." );
8483 return ;
@@ -87,36 +86,45 @@ public void addTool(String name, String description, McpSchema.JsonSchema inputS
8786 log .warn ("Tool addition is ignored: tool description is blank. [toolName={}]" , name );
8887 return ;
8988 }
90- if (inputSchema == null ) {
89+ if (MapUtils . isEmpty ( parameters ) ) {
9190 log .warn ("Tool addition is ignored: tool schema is null or empty. [toolName={}]" , name );
9291 return ;
9392 }
94- if (callHandler == null ) {
95- log .warn ("Tool addition is ignored: tool call handler is null or empty. [toolName={}]" , name );
93+ if (!(parameters .get (TYPE ) instanceof String )
94+ || parameters .get (PROPERTIES ) != null && !(parameters .get (PROPERTIES ) instanceof Map )
95+ || parameters .get (REQUIRED ) != null && !(parameters .get (REQUIRED ) instanceof List )) {
96+ log .warn ("Invalid parameter schema. [toolName={}]" , name );
9697 return ;
9798 }
98-
99+ @ SuppressWarnings ("unchecked" )
100+ McpSchema .JsonSchema inputSchema = new McpSchema .JsonSchema ((String ) parameters .get (TYPE ),
101+ (Map <String , Object >) parameters .get (PROPERTIES ), (List <String >) parameters .get (REQUIRED ),
102+ null , null ,null );
99103 McpServerFeatures .SyncToolSpecification toolSpecification = McpServerFeatures .SyncToolSpecification .builder ()
100104 .tool (McpSchema .Tool .builder ()
101105 .name (name )
102106 .description (description )
103107 .inputSchema (inputSchema )
104108 .build ())
105- .callHandler (callHandler )
109+ .callHandler ((exchange , request ) -> {
110+ Map <String , Object > args = request .arguments ();
111+ String result = this .toolExecuteService .execute (name , args );
112+ return new McpSchema .CallToolResult (result , false );
113+ })
106114 .build ();
107115 this .mcpSyncServer .addTool (toolSpecification );
108116
109117 Tool tool = new Tool ();
110118 tool .setName (name );
111119 tool .setDescription (description );
112- tool .setInputSchema (inputSchema );
120+ tool .setInputSchema (parameters );
113121 this .tools .put (name , tool );
114122 log .info ("Tool added to MCP server. [toolName={}, description={}, schema={}]" , name , description , inputSchema );
115123 this .toolsChangedObservers .forEach (ToolsChangedObserver ::onToolsChanged );
116124 }
117125
118126 @ Override
119- public void removeTool (String name ) {
127+ public void onToolRemoved (String name ) {
120128 if (StringUtils .isBlank (name )) {
121129 log .warn ("Tool removal is ignored: tool name is blank." );
122130 return ;
@@ -126,32 +134,4 @@ public void removeTool(String name) {
126134 log .info ("Tool removed from MCP server. [toolName={}]" , name );
127135 this .toolsChangedObservers .forEach (ToolsChangedObserver ::onToolsChanged );
128136 }
129-
130- @ Override
131- public void onToolAdded (String name , String description , Map <String , Object > parameters ) {
132- if (MapUtils .isEmpty (parameters )) {
133- log .warn ("Tool addition is ignored: tool schema is null or empty. [toolName={}]" , name );
134- return ;
135- }
136- if (!(parameters .get (TYPE ) instanceof String )
137- || parameters .get (PROPERTIES ) != null && !(parameters .get (PROPERTIES ) instanceof Map )
138- || parameters .get (REQUIRED ) != null && !(parameters .get (REQUIRED ) instanceof List )) {
139- log .warn ("Invalid parameter schema. [toolName={}]" , name );
140- return ;
141- }
142- @ SuppressWarnings ("unchecked" )
143- McpSchema .JsonSchema hkxSchema = new McpSchema .JsonSchema ((String ) parameters .get (TYPE ),
144- (Map <String , Object >) parameters .get (PROPERTIES ), (List <String >) parameters .get (REQUIRED ),
145- null , null ,null );
146- this .addTool (name , description , hkxSchema , (exchange , request ) -> {
147- Map <String , Object > args = request .arguments ();
148- String result = this .toolExecuteService .execute (name , args );
149- return new McpSchema .CallToolResult (result , false );
150- });
151- }
152-
153- @ Override
154- public void onToolRemoved (String name ) {
155- this .removeTool (name );
156- }
157137}
0 commit comments