Refactor MCP server and enhance development environment

This commit refactors the MCP server implementation, updates the Dockerfile with new development tools and dependencies, introduces a Makefile for building and running the application, and adds utility modules for sandbox management and Ollama integration. The server name has also been updated from 'echo-server' to 'PMO-Crazy-coder' in the configuration.
This commit is contained in:
2026-01-25 17:24:46 +01:00
parent 9f9d9bc3b3
commit 766b90a548
16 changed files with 536 additions and 8 deletions

View File

@@ -0,0 +1,50 @@
import json
import re
from ollama import prompt
def structure_to_json(text, schema):
"""
Convert structured text to JSON using Ollama.
Args:
text (str): The structured text to convert
schema (dict): The JSON schema to use for conversion
Returns:
dict: The parsed JSON object
"""
# Format the schema as JSON string
schema_json = json.dumps(schema, indent=2)
# Create the prompt following the pattern from your bash command
full_prompt = f"""Transform the following structured text into JSON according to the given schema.
**Return only valid JSON, without any Markdown formatting :**
- no backticks,
- no code blocks,
- no extra text
Input text:
{text}
Schema:
{schema_json}"""
# Send to Ollama
response = prompt("ollama:qwen3:0.6b", full_prompt, allow_pull=True)
# Remove any markdown formatting (backticks, code blocks) that Ollama might include
# Only remove backticks at the beginning or end of the response, not those within the JSON
clean_response = response.strip()
while clean_response.startswith("`") or clean_response.startswith("```"):
clean_response = clean_response[1:].strip()
while clean_response.endswith("`") or clean_response.endswith("```"):
clean_response = clean_response[:-1].strip()
# Try to parse the response as JSON
try:
return json.loads(clean_response)
except json.JSONDecodeError:
# If parsing fails, return the raw response
return {"error": "Failed to parse JSON", "raw_response": clean_response}