From c6b70103924f8cad2aa267314aa50b562b00376b Mon Sep 17 00:00:00 2001 From: KaisHasan Date: Wed, 8 Oct 2025 13:59:07 +0300 Subject: [PATCH 1/3] add python cache folders to the git ignore list --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 53efcb5..da683f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .apm Build/ +__pycache__ From ccae913357e439f6b1d91b3e89ab39328710a6f7 Mon Sep 17 00:00:00 2001 From: KaisHasan Date: Wed, 8 Oct 2025 13:59:39 +0300 Subject: [PATCH 2/3] write the mcp server code in flask --- mcp/__init__.py | 0 mcp/app.py | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ mcp/tools.json | 17 ++++++++ 3 files changed, 131 insertions(+) create mode 100644 mcp/__init__.py create mode 100644 mcp/app.py create mode 100644 mcp/tools.json diff --git a/mcp/__init__.py b/mcp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mcp/app.py b/mcp/app.py new file mode 100644 index 0000000..6644e92 --- /dev/null +++ b/mcp/app.py @@ -0,0 +1,114 @@ +import json + +from flask import Flask, request, jsonify + +from copilot_server.agents import BasicExamplesRetriever + +app = Flask(__name__) + +global_id = 0 +BASIC_VDB_PATH = 'vdb_basic.index' +BASIC_EXAMPLES_INDEX_PATH = 'index.json' + +basic_examples_retriever = BasicExamplesRetriever(BASIC_VDB_PATH, BASIC_EXAMPLES_INDEX_PATH, debug=True) + + +with open("mcp/tools.json", "r", encoding="utf-8") as tools_file: + TOOLS = json.load(tools_file) + + +def initialize_mcp(id): + return jsonify({ + "jsonrpc": "2.0", + "id": id, + "result": { + "protocolVersion": "2025-06-18", + "serverInfo": {"name": "alusus-docs", "version": "1.0.0"}, + "capabilities": {"tools": {"listChanged": True}, "resources": {}} + } + }) + + +def retrieve_docs(query): + docs = basic_examples_retriever.get_docs(query, k=10) + + return docs + + +def get_tool(tool_name): + if tool_name == 'alusus_docs_retrieve': + return retrieve_docs + else: + return None + + +@app.route('/mcp', methods=['POST']) +def mcp(): + payload = request.get_json(force=True) + print(f'payload: {payload}') + + jsonrpc = payload.get("jsonrpc") + method = payload.get("method") + id_ = payload.get("id") + + if method == 'initialize': + return initialize_mcp(id_) + + if method == 'notifications/initialized': + return jsonify({ + "jsonrpc": "2.0", + "method": "notifications/initialized", + "params": {} + }, 200) + + if method == 'tools/list': + return jsonify({ + "jsonrpc": "2.0", + "id": id_, + "result": {"tools": TOOLS} + }) + + if method == 'ping': + return jsonify({ + "jsonrpc": "2.0", + "id": id_, + "result": {} + }) + + if method == 'tools/call': + params = payload.get("params") + if params is not None: + tool_name = params.get("name") + args = params.get("arguments") + + tool = get_tool(tool_name) + + if tool is None: + return ("Bad Request, invalid tool name", 400) + + results = tool(**args) + + content = [{"type": "text", "text": item} for item in results] + + return jsonify({ + "jsonrpc": "2.0", + "id": id_, + "result": { + "content": content + } + }) + else: + return ("Bad Request, include required parameters to invoke the tool", 400) + + +@app.route('/query', methods=['POST']) +def handle_query(): + data = request.json + + print(f'data:\n {data}') + + return jsonify({"response": "message reached the server!!"}) + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/mcp/tools.json b/mcp/tools.json new file mode 100644 index 0000000..53a6859 --- /dev/null +++ b/mcp/tools.json @@ -0,0 +1,17 @@ +[ + { + "name": "alusus_docs_retrieve", + "title": "Alusus Docs", + "description": "Retrieve documentation for a given query about Alusus programming language", + "inputSchema": { + "type": "object", + "properties": { + "query": { + "type": "string", + "description": "The user question about Alusus programming language" + } + }, + "required": ["query"] + } + } +] From 13dbd8d8f67f581e19fd4365636294746a6b6bb9 Mon Sep 17 00:00:00 2001 From: KaisHasan Date: Wed, 8 Oct 2025 14:00:38 +0300 Subject: [PATCH 3/3] configure opencode to use the mcp test server --- opencode/config.json | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 opencode/config.json diff --git a/opencode/config.json b/opencode/config.json new file mode 100644 index 0000000..53172f5 --- /dev/null +++ b/opencode/config.json @@ -0,0 +1,39 @@ +{ + "$schema": "https://opencode.ai/config.json", + "agent": { + "alusus-server": { + "mode": "subagent", + "description": "Posts user input to my HTTP endpoint and returns the JSON response", + "model": "openai/o4-mini", + "prompt": "Take the user’s question, POST `{ \"input\": \"\" }` to http://127.0.0.1:5000/query , then return the parsed JSON." + }, + + "alusus-simple": { + "mode": "subagent", + "description": "Clean the user query and retrieve docs from the correct mcp", + "prompt": "When the user asks about the Alusus programming language, Clean the user’s question by removing filler words, trailing punctuation, and convert it to a concise form. Then take it and, POST `{ \"query\": \"\" }` to http://127.0.0.1:5000/retrieve-docs. Once the tool returns, compose a final answer grounded in the returned 'docs' field.", + "model": "openai/o4-mini" + }, + + "alusus-docs": { + "mode": "subagent", + "description": "Posts user input to my mcp endpoint and returns the JSON response", + "model": "openai/o4-mini", + "prompt": "Use the mcp \"alusus-docs\" to retrieve docs through the tool `alusus_docs_retrieve`, the mcp use http, so do the initialization and all steps required for that." + }, + }, + + + "mcp": { + "alusus-docs": { + "type": "remote", + "url": "http://127.0.0.1:5000/mcp", + "enabled": true + } + }, + + "tools": { + // Enable all tools from the docs server + "alusus-docs_*": true + } +}