This commit is contained in:
2025-05-04 08:19:47 +03:00
parent d8a59d0726
commit 46e1c6706c
177 changed files with 5708 additions and 5512 deletions

View File

@@ -8,7 +8,7 @@ fn main() {
eprintln('Failed to create MCP server: ${err}')
return
}
// Start the server
server.start() or {
eprintln('Failed to start MCP server: ${err}')

View File

@@ -15,11 +15,11 @@ pub fn new_mcp_server(v &VCode) !&mcp.Server {
mut server := mcp.new_server(mcp.MemoryBackend{
tools: {
'get_function_from_file': get_function_from_file_tool
'write_vfile': write_vfile_tool
'write_vfile': write_vfile_tool
}
tool_handlers: {
'get_function_from_file': v.get_function_from_file_tool_handler
'write_vfile': v.write_vfile_tool_handler
'write_vfile': v.write_vfile_tool_handler
}
}, mcp.ServerParams{
config: mcp.ServerConfiguration{
@@ -30,4 +30,4 @@ pub fn new_mcp_server(v &VCode) !&mcp.Server {
}
})!
return server
}
}

View File

@@ -3,7 +3,7 @@ module vcode
import freeflowuniverse.herolib.mcp
import freeflowuniverse.herolib.core.code
import freeflowuniverse.herolib.schemas.jsonschema
import x.json2 {Any}
import x.json2 { Any }
const get_function_from_file_tool = mcp.Tool{
name: 'get_function_from_file'
@@ -16,10 +16,10 @@ RETURNS: string - the function block including comments, or empty string if not
typ: 'object'
properties: {
'file_path': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'string'
typ: 'string'
})
'function_name': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'string'
typ: 'string'
})
}
required: ['file_path', 'function_name']

View File

@@ -3,7 +3,7 @@ module vcode
import freeflowuniverse.herolib.mcp
import freeflowuniverse.herolib.core.code
import freeflowuniverse.herolib.schemas.jsonschema
import x.json2 {Any}
import x.json2 { Any }
const write_vfile_tool = mcp.Tool{
name: 'write_vfile'
@@ -18,20 +18,20 @@ RETURNS: string - success message with the path of the written file'
input_schema: jsonschema.Schema{
typ: 'object'
properties: {
'path': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'string'
'path': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'string'
})
'code': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'string'
'code': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'string'
})
'format': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'boolean'
'format': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'boolean'
})
'overwrite': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'boolean'
typ: 'boolean'
})
'prefix': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'string'
'prefix': jsonschema.SchemaRef(jsonschema.Schema{
typ: 'string'
})
}
required: ['path', 'code']
@@ -41,31 +41,27 @@ RETURNS: string - success message with the path of the written file'
pub fn (d &VCode) write_vfile_tool_handler(arguments map[string]Any) !mcp.ToolCallResult {
path := arguments['path'].str()
code_str := arguments['code'].str()
// Parse optional parameters with defaults
format := if 'format' in arguments { arguments['format'].bool() } else { false }
overwrite := if 'overwrite' in arguments { arguments['overwrite'].bool() } else { false }
prefix := if 'prefix' in arguments { arguments['prefix'].str() } else { '' }
// Create write options
options := code.WriteOptions{
format: format
format: format
overwrite: overwrite
prefix: prefix
prefix: prefix
}
// Parse the V code string into a VFile
vfile := code.parse_vfile(code_str) or {
return mcp.error_tool_call_result(err)
}
vfile := code.parse_vfile(code_str) or { return mcp.error_tool_call_result(err) }
// Write the VFile to the specified path
vfile.write(path, options) or {
return mcp.error_tool_call_result(err)
}
vfile.write(path, options) or { return mcp.error_tool_call_result(err) }
return mcp.ToolCallResult{
is_error: false
content: mcp.result_to_mcp_tool_contents[string]('Successfully wrote V file to ${path}')
content: mcp.result_to_mcp_tool_contents[string]('Successfully wrote V file to ${path}')
}
}

View File

@@ -8,47 +8,47 @@ import os
pub fn handler(arguments map[string]Any) !mcp.ToolCallResult {
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")
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 := ""
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}")
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(".v") {
} else if path.ends_with('.v') {
// 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}")
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")
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: mcp.result_to_mcp_tool_contents[string](message)
content: mcp.result_to_mcp_tool_contents[string](message)
}
}

View File

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