From f97da41595615ffd1bce0d06b831ab0d358c4d2b Mon Sep 17 00:00:00 2001 From: syui Date: Thu, 22 May 2025 21:30:47 +0900 Subject: [PATCH] add mcp --- .gitignore | 1 + README.md | 2 +- mcp/cli.py | 27 +++++++++++++- mcp/scripts/ask.py | 75 +++++++++++++-------------------------- mcp/scripts/config.py | 34 ++++++++++++++++++ mcp/scripts/summarize.py | 76 ++++++++++++++++++++++++++++++++++++++++ mcp/setup.py | 1 + src/chat.rs | 7 ++-- src/commands/mcp.rs | 2 ++ 9 files changed, 168 insertions(+), 57 deletions(-) create mode 100644 mcp/scripts/config.py create mode 100644 mcp/scripts/summarize.py diff --git a/.gitignore b/.gitignore index f87909d..29a2f58 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ output.json config/*.db aigpt +mcp/scripts/__* diff --git a/README.md b/README.md index 2db50e4..c3b84c0 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ $ ./aigpt mcp chat "hello world!" --host http://localhost:11434 --model syui/ai --- # openai api -$ ./aigpt mcp set-api -api sk-abc123 +$ ./aigpt mcp set-api --api sk-abc123 $ ./aigpt mcp chat "こんにちは" -p openai -m gpt-4o-mini --- diff --git a/mcp/cli.py b/mcp/cli.py index 5164c4c..9949254 100644 --- a/mcp/cli.py +++ b/mcp/cli.py @@ -1,3 +1,28 @@ # cli.py +import sys +import subprocess +from pathlib import Path + +SCRIPT_DIR = Path.home() / ".config" / "aigpt" / "mcp" / "scripts" +def run_script(name): + script_path = SCRIPT_DIR / f"{name}.py" + if not script_path.exists(): + print(f"❌ スクリプトが見つかりません: {script_path}") + sys.exit(1) + + args = sys.argv[2:] # ← "ask" の後の引数を取り出す + result = subprocess.run(["python", str(script_path)] + args, capture_output=True, text=True) + print(result.stdout) + if result.stderr: + print(result.stderr) def main(): - print("Hello MCP!") + if len(sys.argv) < 2: + print("Usage: mcp