EL

ecko-lang/mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

2 stars 0 forks 质量 59 趋势 28MIT

Model Context Protocol for Ecko, both directions: call an MCP server's tools, or be one.

概览

Model Context Protocol, both directions. Call an MCP server's tools, or be one. MCP is JSON-RPC 2.0 with a fixed vocabulary: a handshake, then tools/, resources/ and prompts/*. MCP goes both directions: this package speaks to a server, and lets you be one. Register it with a client by pointing it at ecko your_server.ecko. is how almost every MCP server ships: the client starts the process and uses the pipes it already has, so there is no port and nothing to authenticate. Needs . is the shape a hosted server takes. Needs . is a transport backed by a function, for tests. Needs no capability at all. offer is { tools, resources, prompts }, each optional. A bare list is taken as the tools.

README

以下为原文 README 节选,完整内容请查看原文。

mcp

Model Context Protocol, both directions. Call an MCP server’s tools, or be one.

MCP is JSON-RPC 2.0 with a fixed vocabulary: a handshake, then tools/*, resources/* and prompts/*.

Install

ecko get github.com/ecko-lang/mcp

Usage

MCP goes both directions: this package speaks to a server, and lets you be one.

Calling a server

import mcp

session = mcp.connect(mcp.stdio_transport("npx", ["-y", "@some/mcp-server"]))

for t in mcp.tools(session) {
    print("{t.name}: {t.description}")
}

print(mcp.text_of(mcp.call_tool(session, "search", { query: "ecko" })))
mcp.close(session)

Hand the tools straight to a model:

answer = ai "what changed in the changelog?" using mcp.as_tools(session)

Being a server

import mcp

mcp.serve_stdio([
    mcp.tool(
        "word_count",
        "Count the words in some text",
        { type: "object", properties: { text: { type: "string" } }, required: ["text"] },
        fn(args) len(split(trim(args.text), " ")),
    ),
], { name: "words", version: "1.0" })

Register it with a client by pointing it at ecko your_server.ecko.

Transports

stdio is how almost every MCP server ships: the client starts the process and uses the pipes it already has, so there is no port and nothing to authenticate. Needs exec.

mcp.stdio_transport("npx", ["-y", "@some/mcp-server"], { timeout_ms: 30000 })

HTTP is the shape a hosted server takes. Needs net.

token = secret(os.env("MCP_TOKEN"))
mcp.http_transport("https://mcp.example.com/", {
    headers: { Authorization: "Bearer {reveal(token)}" },
})

mcp.fake(handler) is a transport backed by a function, for tests. Needs no capability at all.

API

Client

call result
mcp.connect(transport, info?) Handshake and return a session.
mcp.close(session) Close the transport.
mcp.server_version(session) / mcp.server_capabilities(session) What the server answered with.
mcp.tools(session) Every tool, following pagination.
mcp.call_tool(session, name, args?) The raw result: content, maybe isError.
mcp.text_of(result) / mcp.is_error(result) The text parts; whether the tool failed.
mcp.as_tools(session) / mcp.as_tool(session, t) Tool specs for ai ... using.
mcp.resources(session) / mcp.read_resource(session, uri) Resources.
mcp.prompts(session) / mcp.get_prompt(session, name, args?) Prompts.
mcp.cancel(session, id, reason?) / mcp.next_request_id(session) Cancel a request.
mcp.call(session, method, params?) / mcp.notify(...) Anything not wrapped above.
mcp.request(id, method, params?) / mcp.notification(method, params?) / mcp.encode(message) Build and encode a raw JSON-RPC message.

Server

call result
mcp.serve_stdio(offer, info?) / mcp.serve_http(port, offer, info?) Serve. Blocks.
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →