This commit is contained in:
2025-04-04 14:02:17 +02:00
parent 8a10374570
commit e5de293919
6 changed files with 61 additions and 21 deletions

View File

@@ -8,6 +8,13 @@ The MCP module serves as a core library for building MCP-compliant servers in V.
The module implements all the required MCP protocol methods (resources/list, tools/list, prompts/list, etc.) and manages the underlying JSON-RPC communication, allowing developers to focus solely on implementing their specific tools and handlers. The module itself is not a standalone server but rather a framework that can be used to build different MCP server implementations. The subdirectories within this module (such as `baobab` and `developer`) contain specific implementations of MCP servers that utilize this core framework.
## to test
```
curl -fsSL https://bun.sh/install | bash
source /root/.bashrc
```
## Key Components
- **Server**: The main MCP server struct that handles JSON-RPC requests and responses

View File

@@ -5,10 +5,10 @@ set -ex
cd "$(dirname "$0")"
# Compile the V program
v -n -w -gc none -cc tcc -d use_openssl -enable-globals .
v -n -w -gc none -cc tcc -d use_openssl -enable-globals main.v
# Ensure the binary is executable
chmod +x main
rm main pugconvert
mv main ~/hero/bin/pugconvert
echo "Compilation successful. Binary 'main' is ready."

View File

@@ -14,10 +14,4 @@ fn main() {
eprintln('Failed to start MCP server: ${err}')
return
}
// Wait for server to complete
server.wait() or {
eprintln('Error while running MCP server: ${err}')
return
}
}

View File

@@ -2,15 +2,53 @@ module pugconvert
import freeflowuniverse.herolib.mcp
import x.json2 as json { Any }
import freeflowuniverse.herolib.mcp.logger
import freeflowuniverse.herolib.baobab.generator
import freeflowuniverse.herolib.mcp.aitools.pugconvert
import freeflowuniverse.herolib.core.pathlib
import os
pub fn handler(arguments map[string]Any) !mcp.ToolCallResult {
println('debugzo31')
path := arguments['path'].str()
// Check if path exists
if !os.exists(path) {
return mcp.ToolCallResult{
is_error: true
content: mcp.result_to_mcp_tool_contents[string]("Error: Path '${path}' does not exist")
}
}
// Determine if path is a file or directory
is_directory := os.is_dir(path)
mut message := ""
if is_directory {
// Convert all pug files in the directory
pugconvert.convert_pug(path) or {
return mcp.ToolCallResult{
is_error: true
content: mcp.result_to_mcp_tool_contents[string]("Error converting pug files in directory: ${err}")
}
}
message = "Successfully converted all pug files in directory '${path}'"
} else if path.ends_with(".pug") {
// Convert a single pug file
pugconvert.convert_pug_file(path) or {
return mcp.ToolCallResult{
is_error: true
content: mcp.result_to_mcp_tool_contents[string]("Error converting pug file: ${err}")
}
}
message = "Successfully converted pug file '${path}'"
} else {
return mcp.ToolCallResult{
is_error: true
content: mcp.result_to_mcp_tool_contents[string]("Error: Path '${path}' is not a directory or .pug file")
}
}
return mcp.ToolCallResult{
is_error: false
content: result_to_mcp_tool_contents[string](result)
content: mcp.result_to_mcp_tool_contents[string](message)
}
}

View File

@@ -10,10 +10,10 @@ pub fn new_mcp_server() !&mcp.Server {
// Initialize the server with the empty handlers map
mut server := mcp.new_server(mcp.MemoryBackend{
tools: {
'generate_module_from_openapi': specs
'pugconvert': specs
}
tool_handlers: {
'generate_module_from_openapi': generate_module_from_openapi_tool_handler
'pugconvert': handler
}
}, mcp.ServerParams{
config: mcp.ServerConfiguration{

View File

@@ -2,18 +2,19 @@ module pugconvert
import freeflowuniverse.herolib.mcp
import x.json2 as json { Any }
import freeflowuniverse.herolib.schemas.jsonschema
import freeflowuniverse.herolib.mcp.logger
import freeflowuniverse.herolib.baobab.generator
const specs = mcp.Tool{
name: 'pug_convert'
description: ''
input_schema: mcp.ToolInputSchema{
name: 'pugconvert'
description: 'Convert Pug template files to Jet template files'
input_schema: jsonschema.Schema{
typ: 'object'
properties: {
'path': mcp.ToolProperty{
typ: 'string'
}
'path': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'string',
description: 'Path to a .pug file or directory containing .pug files to convert'
})
}
required: ['path']
}