-
Notifications
You must be signed in to change notification settings - Fork 627
Improve Scenario Generation Using MCP Server #448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cielonet
wants to merge
4
commits into
OpenPipe:main
Choose a base branch
from
cielonet:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+630
−130
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| """Simple MCP server for formatting scenario data into JSON via stdio.""" | ||
|
|
||
| import json | ||
| import sys | ||
| from typing import Any, Dict | ||
|
|
||
|
|
||
| def send_response(id: Any, result: Dict[str, Any]) -> None: | ||
| """Send JSON-RPC response.""" | ||
| response = {"jsonrpc": "2.0", "id": id, "result": result} | ||
| print(json.dumps(response), flush=True) | ||
|
|
||
|
|
||
| def send_error(id: Any, code: int, message: str) -> None: | ||
| """Send JSON-RPC error.""" | ||
| response = {"jsonrpc": "2.0", "id": id, "error": {"code": code, "message": message}} | ||
| print(json.dumps(response), flush=True) | ||
|
|
||
|
|
||
| def handle_request(request: Dict[str, Any]) -> None: | ||
| """Handle MCP protocol request.""" | ||
| method = request.get("method") | ||
| params = request.get("params", {}) | ||
| req_id = request.get("id") | ||
|
|
||
| if method == "initialize": | ||
| send_response( | ||
| req_id, | ||
| { | ||
| "protocolVersion": "2024-11-05", | ||
| "serverInfo": {"name": "scenario-formatter", "version": "1.0.0"}, | ||
| "capabilities": {"tools": {}}, | ||
| }, | ||
| ) | ||
|
|
||
| elif method == "notifications/initialized": | ||
| # Client acknowledges initialization - no response needed | ||
| pass | ||
|
|
||
| elif method == "tools/list": | ||
| send_response( | ||
| req_id, | ||
| { | ||
| "tools": [ | ||
| { | ||
| "name": "format_scenario", | ||
| "description": "Format a scenario into proper JSON structure", | ||
| "inputSchema": { | ||
| "type": "object", | ||
| "properties": { | ||
| "task": {"type": "string", "description": "The task description"}, | ||
| "difficulty": { | ||
| "type": "integer", | ||
| "description": "Difficulty rating from 1-5", | ||
| }, | ||
| }, | ||
| "required": ["task", "difficulty"], | ||
| }, | ||
| } | ||
| ] | ||
| }, | ||
| ) | ||
|
|
||
| elif method == "tools/call": | ||
| tool_name = params.get("name") | ||
| args = params.get("arguments", {}) | ||
|
|
||
| if tool_name == "format_scenario": | ||
| # Format and validate the scenario | ||
| formatted = { | ||
| "task": str(args.get("task", "")).strip(), | ||
| "difficulty": max(1, min(5, int(args.get("difficulty", 3)))), | ||
| } | ||
|
|
||
| send_response( | ||
| req_id, | ||
| {"content": [{"type": "text", "text": json.dumps(formatted, indent=2)}]}, | ||
| ) | ||
| else: | ||
| send_error(req_id, -32601, f"Unknown tool: {tool_name}") | ||
|
|
||
| elif method and method.startswith("notifications/"): | ||
| # Handle other notifications silently | ||
| pass | ||
|
|
||
| else: | ||
| if req_id: # Only send error if there's an ID to respond to | ||
| send_error(req_id, -32601, f"Unknown method: {method}") | ||
|
|
||
|
|
||
| def main(): | ||
| """Main server loop.""" | ||
| buffer = "" | ||
| for line in sys.stdin: | ||
| buffer += line | ||
| try: | ||
| request = json.loads(buffer) | ||
| buffer = "" | ||
| handle_request(request) | ||
| except json.JSONDecodeError: | ||
| # Not complete JSON yet, keep buffering | ||
| continue | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a true MCP stdio server... could make better... but works