Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.apm
Build/
__pycache__
Empty file added mcp/__init__.py
Empty file.
114 changes: 114 additions & 0 deletions mcp/app.py
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions mcp/tools.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
]
39 changes: 39 additions & 0 deletions opencode/config.json
Original file line number Diff line number Diff line change
@@ -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\": \"<question>\" }` 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\": \"<question>\" }` 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
}
}