OpenAI API で複数言語に対応した翻訳 CLI ツール translate-mcp の開発
· 約4分
translate-mcp は OpenAI の API を使った翻訳ツールである。CLI モードと MCP サーバーの両方の利用方法に対応している。 ファイル全体を翻訳したい場合から、AI ツールに統合して使いたい場合まで、幅広いシーンで活躍する。
translate-mcp は OpenAI の API を使った翻訳ツールである。CLI モードと MCP サーバーの両方の利用方法に対応している。 ファイル全体を翻訳したい場合から、AI ツールに統合して使いたい場合まで、幅広いシーンで活躍する。
MCP を使用した場合、LLM クライアントでどのような流れで処理が行われるかを Copilot くんに聞きました。
以下、シーケンス図です。
ここで重要なのは、
です。
MCP にかかわる部分は、1. と 4. で、 Function calling とほぼ同じ部分が 2. と 3. と 5. です。
ローカル MCP を標準入力で使用してみましょう。
Windows PowerShell を用いてコマンドをたたきます。
例として @modelcontextprotocol/server-filesystem のツール一覧を取得します。
> @{ jsonrpc = "2.0"; method = "tools/list"; id = 1 } | ConvertTo-Json -Compress | npx @modelcontextprotocol/server-filesystem $HOME | ConvertFrom-Json | ConvertTo-Json -Depth 10
Secure MCP Filesystem Server running on stdio
Allowed directories: [ 'C:\\Users\\hikari' ]
{
"result": {
"tools": [
{
"name": "read_file",
"description": "Read the complete contents of a file from the file system. Handles various text encodings and provides detailed error messages if the file cannot be read. Use this tool when you need to examine the contents of a single file. Only works within allowed directories.",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string"
}
},
"required": [
"path"
],
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#"
}
},
...
]
}
}
tools/list を標準入力で与えることで、ツール一覧を JSON 形式で取得できます。
ツールの情報をもとに呼び出してみます。
> @{ jsonrpc = "2.0"; method = "tools/call"; params = @{name = "read_file"; arguments = @{path = ".gitconfig"}}; id = 2 } | ConvertTo-Json -Compress -Depth 10 | npx @modelcontextprotocol/server-filesystem $HOME | ConvertFrom-Json | ConvertTo-Json -Depth 10
Secure MCP Filesystem Server running on stdio
Allowed directories: [ 'C:\\Users\\hikari' ]
{
"result": {
"content": [
{
"type": "text",
"text": "..."
}
]
},
"jsonrpc": "2.0",
"id": 2
}