mcp fixes wip

This commit is contained in:
Timur Gordon
2025-03-15 10:29:24 +01:00
parent ef922d162e
commit dc178f68c7
8 changed files with 55 additions and 4 deletions

View File

@@ -21,7 +21,7 @@ interface Backend {
tool_exists(name string) !bool
tool_get(name string) !Tool
tool_list() ![]Tool
tool_call(name string, arguments map[string]string) !ToolCallResult
tool_call(name string, arguments map[string]Any) !ToolCallResult
mut:
resource_subscribe(uri string) !
resource_unsubscribe(uri string) !

View File

@@ -118,7 +118,7 @@ fn (b &MemoryBackend) tool_list() ![]Tool {
return b.tools.values()
}
fn (b &MemoryBackend) tool_call(name string, arguments map[string]string) !ToolCallResult {
fn (b &MemoryBackend) tool_call(name string, arguments map[string]Any) !ToolCallResult {
// Get the tool handler
handler := b.tool_handlers[name] or { return error("tool handler not found") }

View File

@@ -19,3 +19,11 @@ const create_mcp_tool_tool = mcp.Tool{
required: ['function']
}
}
pub fn (d &Developer) create_mcp_tool_tool_handler(arguments map[string]string) !mcp.Tool {
json.decode(arguments)
// TODO: Implement the tool creation logic
return error('Not implemented')
return mcp.tool_call_result(result)
}

View File

@@ -0,0 +1,34 @@
module developer
import freeflowuniverse.herolib.mcp.logger
import freeflowuniverse.herolib.mcp
import freeflowuniverse.herolib.schemas.jsonrpc
fn new_mcp_server() {
logger.info('Creating new Developer MCP server')
// Initialize the server with the empty handlers map
mut server := mcp.new_server(
mcp.MemoryBackend{
resources: map[string]mcp.Resource{},
resource_contents: map[string][]mcp.ResourceContent{},
resource_templates: map[string]mcp.ResourceTemplate{},
prompts: map[string]mcp.Prompt{},
prompt_messages: map[string][]mcp.PromptMessage{},
tools: map[string]mcp.Tool{},
tool_handlers: map[string]mcp.ToolHandler{},
},
mcp.ServerParams{
config:mcp.ServerConfiguration{
server_info: mcp.ServerInfo{
name: 'developer'
version: '1.0.0'
}
}}
)!
server.start() or {
logger.fatal('Error starting server: $err')
exit(1)
}
}

View File

@@ -3,6 +3,8 @@ module developer
import freeflowuniverse.herolib.mcp
import os
// list_v_files returns all .v files in a directory (non-recursive), excluding generated files ending with _.v
fn list_v_files(dir string) ![]string {
files := os.ls(dir) or {

7
lib/mcp/generics.v Normal file
View File

@@ -0,0 +1,7 @@
module mcp
pub type Any = []Any
| bool
| int
| map[string]Any
| string

View File

@@ -79,7 +79,7 @@ fn (mut s Server) tools_list_handler(data string) !string {
pub struct ToolCallParams {
pub:
name string
arguments map[string]string
arguments map[string]Any
}
pub struct ToolCallResult {

View File

@@ -3,4 +3,4 @@ module mcp
import x.json2
// ToolHandler is a function type that handles tool calls
pub type ToolHandler = fn (arguments map[string]string) !ToolCallResult
pub type ToolHandler = fn (arguments map[string]Any) !ToolCallResult