From 969868ccda95152d5f62f4385d3a1a09cdc7ce79 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 30 Oct 2026 12:41:18 +0800 Subject: [PATCH] library: a Python MCP server in a GitHub repository's folder is found and added filled in (CyberCaius on Discord) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CyberCaius pasted https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_askecho_search_infinity (Volcengine's askecho web search) into the Library's MCP search. The fragment was dropped, the MCP Registry was asked for "mcp-server" and "volcengine", nothing it lists is there, so the page offered only a blank command named "server". A GitHub address naming a folder (#subdirectory=, /tree//…, /blob//…/file) is now read before the registry: the folder's pyproject.toml names the program ([project.scripts]) and its README's "env": {…} examples the keys. It is offered as a normal market card: uvx --from git+https://github.com/o/r[@ref]#subdirectory= , with the keys asked for in the install sheet. Of several keys none is required (askecho takes an API key, or an access key and secret); one alone is. A bare repository is read that way only when the registry has nothing at it. A pypi.org/project/ page, or a one-word search naming mcp (with - _ or .) that the registry lists nothing by, asks PyPI's JSON API and offers uvx with its description's keys. Claude Desktop is already wired for local Library servers (claude_desktop_config.json); the test installs it there. Run (mote): - go test ./internal/library -run 'TestMarket|TestParseRepoAt|TestEnvInputs': ok - go test ./internal/library rebased on ceef9e943 (AnySearch d05482bab in): ok; the push then rebased onto 70a0c387c (agent, cli only), not run again - Full suite go test -timeout 45m ./... at d29414c1a (rebased only onto origin/main since): 78 ok; reds in internal/gateway (Antigravity turned-away x4, TestCodexSpentGrokFailingIsTold) and internal/gui (AppKit real-window tests). Same reds on fresh origin/main ceef9e943, filed as #4362, #2645, #4125, #1936, #3178, #3949. - GOOS=linux/windows/darwin go vet ./internal/library: ok; gofmt clean. - Broken by hand: MarketServers back on searchRegistryAt/searchRegistry, TestMarketServerInRepoFolder, ...RepoFolderPage and ...OnPyPI red. - Real use: the search against live GitHub and PyPI returns the uvx command and the three keys; the command itself, run with uvx and a fake key, answered initialize and listed web_search. - Fixtures are the real pyproject.toml, README.md and PyPI entry, in testdata/askecho; tests reach no network. Not tried: a real search with a real Volcengine key; Claude Desktop launching it (Desktop needs uvx and git on its PATH, as for the featured fetch/git/time servers); Node servers in a folder (still the blank form); a word search like "askecho" (no index has it). No GUI change. --- docs/subsystems/library.md | 1 + internal/library/market.go | 7 +- internal/library/market_repo.go | 386 ++++++++++++++++++ internal/library/market_repo_test.go | 183 +++++++++ internal/library/testdata/askecho/README.md | 177 ++++++++ internal/library/testdata/askecho/pypi.json | 10 + .../library/testdata/askecho/pyproject.toml | 17 + 7 files changed, 778 insertions(+), 3 deletions(-) create mode 100644 internal/library/market_repo.go create mode 100644 internal/library/market_repo_test.go create mode 100644 internal/library/testdata/askecho/README.md create mode 100644 internal/library/testdata/askecho/pypi.json create mode 100644 internal/library/testdata/askecho/pyproject.toml diff --git a/docs/subsystems/library.md b/docs/subsystems/library.md index f4b856a94..ecf3a55e7 100644 --- a/docs/subsystems/library.md +++ b/docs/subsystems/library.md @@ -22,6 +22,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it. | Instructions | magpie's part of an agent's instructions file sits between two marker lines. The rest of the file is the user's. Several named sets can be switched between (#106). A set can be kept in a file of the user's own instead of `instruction-sets/` (`InstrSet.File`, 新v学员 on Discord): `~/.agents/AGENTS.md`, which Droid and omp read too. `textPath` reads it, `putText` keeps it aside and writes it but never removes it, removing the set lets go of it, and `linkable` refuses a file magpie writes into (an agent's own instructions, a file with the marker line), the library's own and another set's. The app's `KeepLinked` looks at the file every 30 s and writes a change into the agents (`SyncLinked`). A set's text is read without magpie's part (`setText`), and an agent whose instructions file is, links followed, the file the set on is kept in (`isSetFile`: `instructions.md` linked to `~/.claude/CLAUDE.md`, or both linked to one dotfile) gets no part written into it, and one written before is taken out with every part nested in it: read with its part, each sync wrote the whole file into that part again and it doubled, to gigabytes (#2349, `TestInstructionsSetLinkedToAgentsFile`). `Collect` carries the set's text, not where its file is; `Put` keeps this computer's file for the set and never empties it for a text not carried. Alma's file is `~/.config/alma/USER.md`, which its main chat reads into its system prompt as its owner's profile (0.4.164's `out/main/index.js`; a workspace's `USER.md` is read instead), and whose leading front matter (`name`, `telegram_id`, `discord_id`) is who its bots answer to (#2315, Jie211). The target is a `Profile`: magpie's part goes after the user's, so the front matter stays first, and `ImportInstructions` refuses it, as moving it out would take that front matter out of the file and into every agent's (`TestAlmaInstructionsKeepTheProfile`, `TestAlmaProfileIsNotImported`, `library-alma-profile.test.cjs`). | [`instructions.go`](../../internal/library/instructions.go) | | MCP servers | A `Server` is a command or a URL (`http`, `sse`). `mcpFile` encodes it in each agent's own format (one `mcpFormat` per agent family) and merges it with the user's own fields for that entry. A server's `StartupTimeout` (#3168) goes to Codex alone, as `startup_timeout_sec` in seconds (`RawMcpServerConfig` in codex-rs/config's mcp_types.rs; 0 leaves Codex's own 30s), in the user-wide config.toml and a project's alike. magpie keeps the value it wrote (`Applied.Startup`, `Project.Startup`): one in the entry other than that, or a `startup_timeout_ms`, is the user's and stays as it is (`startupTheirs`), and once it is taken out magpie's goes in again. The editor shows the field only when an agent that takes it is here (`AgentView.Startup`, `mcp_startup_test.go`, `mcp-startup-timeout.test.cjs`). `Also` files get the same servers; `Extra` files are only read when importing. `CheckServers` connects as an agent would and keeps the result in memory only: with each tool's name and the first paragraph of its description (`ToolList`, at most `maxToolList`, a description cut at `maxToolDesc` runes), which the page lists when the server's "N tools" is clicked, following tools/list's `nextCursor` up to `maxToolPages` pages (`listTools`). Each step (initialize, notifications/initialized, tools/list; connect for SSE) has its own budget, 60s for a URL and 30s for a command (`remoteStep`, `stdioStep`), and a timeout names its `Step` and how long it `Waited`; a timeout isn't kept, so the next look asks again (#1467). A command named bare that magpie's PATH lacks is started from where `proc.FindTool` finds it (fnm's Nodes on Windows among the folders), with that folder on the check's PATH, since npx's package runs the node beside it by name (`stdioProgram`, #2685, `TestStdioProgramFindsWhatPathLacks`). The page asks once a session for the servers some agent or project has (`inUse` in plugins/library/client.js); one no agent has shows "not checked" and is checked only when its status is clicked (#1597, `library-mcp-health.test.cjs`). A server checked once is checked again when it changes, its sign-in included, so a server signed in to after a click's "needs sign-in" isn't left showing both (新v学员 on Discord, `mcp-signin-health.test.cjs`). The check sends magpie's sign-in as the gateway does: on a 401 it renews the token once and asks again, and a server that refuses even the renewed token has the sign-in marked run out (`mcpauth.Rejected`, also from the gateway's `/mcp/`), which `ServerHealth.SignIn` carries back so the row's tag says "Sign-in ran out" rather than "Signed in" beside "needs sign-in". A server that refuses the check (401 or 403) but that an agent signed in to on its own is named so (`ServerHealth.AgentSignIn`, `readOwnSignIns` in `mcp_agent_signin.go`): each Claude Code target's `.credentials.json` beside its settings.json, a WSL distro's under the distro's home, is read for a `mcpOAuth` entry of the server's name and URL with a token, and the row says "signed in in Claude Code (Ubuntu)" instead of "needs sign-in" (CyberCaius on Discord: signed in to with Claude Code's /mcp in WSL). The tokens are never sent or kept; a file that can't be read or parsed names nobody, a stopped distro isn't started for it, and on a Mac only the file is read, never the Keychain Claude Code keeps them in. They are part of the check's key, so a sign-in in the agent since is checked anew (`TestCheckNamesAgentsSignedInThemselves`, `library-mcp-health-wsl.test.cjs`). A server that needs OAuth is signed in once in magpie, and agents reach it through the gateway's `/mcp/` (#615). The editor's Sign in saves the form first only when the sign-in is to another server than the saved one (a new server, a name or URL changed), and its button then reads "Save and sign in"; anything else edited (headers, env, arguments) stays unsaved until Save, so Cancel leaves the server as it was (新v学员 on Discord, `mcp-editor-cancel.test.cjs`). A server whose authorization server refuses magpie's dynamic client registration with 401 or 403 admits only the clients it lists (Figma's, #1619): the sign-in fails with `mcpauth.ErrClientRefused`, which says so and that each agent signs in itself, and the agents keep the server's own address. A server whose authorization server has no registration endpoint at all (GitHub's remote server, 新v学员 on Discord) fails with `mcpauth.ErrNoRegistration`, which says to make an OAuth app with the vendor and give it in the editor; the editor then opens its "OAuth app" fields. The app is the server's `oauth` (`OAuthApp`: `clientId`, `clientSecret`, `callbackPort`, Claude Code's names for `--client-id`, `--client-secret` and `--callback-port`), checked on save (HTTP only, a client ID, a port from 1 to 65535), and `SignInServer` signs in as it through `mcpauth.StartWith` without registering. The callback is Claude Code's, `http://localhost:/callback` (its docs' "Use pre-configured OAuth credentials"; 2.1.296 builds it so), listened for on 127.0.0.1 alone as Claude Code does, so an app made for Claude Code signs magpie in as it is; a server that matches the registered URL exactly refuses another host, which is why Claude Code's 2.1.231 went back to `localhost` from 2.1.229's `127.0.0.1` (`TestAppMadeForClaudeCode`). Without a `callbackPort` the port is any free one, which a loopback callback registered without a port takes (GitHub's, RFC 8252); a fixed `callbackPort` is for a vendor that matches the port too. magpie's own registration, when a server has one, still names `127.0.0.1`. The client secret is kept in library.json, as a header's or env's value is: a backup without keys leaves it out, and `WithSecrets` puts back this computer's secret only for the same client ID; no agent is given the app, and the TUI's editor, which doesn't show it, keeps it. GitHub answers a token request's error with a 200 and `error` in the body (`bad_refresh_token`, `incorrect_client_credentials`), which `tokenRequest` reads as the error it is, and a dead refresh token marks the sign-in run out (`github_app_test.go`, `mcp-oauth-app.test.cjs`). magpie never registers under another client's name; one that reaches the gateway from another machine (a WSL distro under NAT) is given it with the LAN sharing key as its `Authorization` (`agent.KeyAt`), as its models are, which the gateway takes in place of a sign-in and never passes on; turning sharing on or off, or a new key (`access.LANChanged`), writes such entries again. `ConfigOfServers` is the servers picked as an agent's project file (`projectMCPFiles`) would hold them, written by the same code into a folder of its own and read back, with those the agent can't take there named; the page's Copy config… puts it on the clipboard for a project magpie doesn't keep (#1478). Each listed tool has a switch: the tools turned off are the server's `DisabledTools`, set by `ServerTools`, and written into each agent given the server that can leave out a single tool (see the constraint below). A server run as `npx -y args` (a registry package, no other npx flag) is given to an agent on this machine as `node args` (`npxDirect`): magpie installs the package with npm into a folder of its own under `mcp-npm` in the background, the next sync writes the node form, and until then, or when npm fails (tried again after an hour), the agent keeps npx. npx otherwise stays as the server's parent for its whole life, a node and two cmd.exe beside each instance on Windows (#3885). An unpinned spec is installed again after a day, as npx would fetch the newer one; an install no library server runs goes a day after its last. The library, a server's check, Copy config… and agents in WSL keep npx (`TestNpxServerRunsByNode`, `TestReadNpx`). | [`mcp.go`](../../internal/library/mcp.go), [`mcp_npx.go`](../../internal/library/mcp_npx.go), [`mcp_check.go`](../../internal/library/mcp_check.go), [`mcp_signin.go`](../../internal/library/mcp_signin.go), [`mcp_agent_signin.go`](../../internal/library/mcp_agent_signin.go), [`mcp_copy.go`](../../internal/library/mcp_copy.go), [`mcp_tools_off.go`](../../internal/library/mcp_tools_off.go) | | MCP hub | With `MCPHub` on, `syncMCP` gives each agent that can take it one entry, `magpie`, at the gateway's `/mcp/magpie/hub/`, in place of the servers ticked for it; magpie runs those servers itself, once for every agent. | [MCP hub](mcp-hub.md), [`mcp_hub.go`](../../internal/library/mcp_hub.go) | +| MCP market | `MarketServers` lists the featured servers that match a search, then the MCP Registry's; a search that is an address (a repository, a page, an endpoint, a package; `market_addr.go`) finds the ones at it, and `CustomAt` offers one to fill in by hand when none is. The registry lists no server by a repository's folder, so a GitHub address naming one (`#subdirectory=`, `/tree//…`, `parseRepoAt`) is read first: the folder's `pyproject.toml` names the program, and the README's `"env": {…}` examples the keys, offered as `uvx --from git+https://github.com/o/r#subdirectory=p ` (`fromRepo`, CyberCaius on Discord: volcengine/mcp-server's askecho search). A bare repository is read so only when the registry has nothing at it, and a PyPI page, or a one-word search naming mcp the registry lists nothing by, asks PyPI (`fromPyPI`, `uvx `). Of several README keys none is required, since a README often has the user pick one way to sign in (`envInputs`; `TestMarketServerInRepoFolder`). Only Python projects are read from a folder; a Node one there still gets the blank form. | [`market.go`](../../internal/library/market.go), [`market_repo.go`](../../internal/library/market_repo.go) | | Skills | A skill is a folder with a `SKILL.md`. It goes by the `name` its front matter gives, made fit for a file name (ASCII letters, digits, `_` and `-`); a name that would lose a letter or digit that way (one in another script, `CTF•密码学`) or none goes by its folder's name instead, and a skill at a repository's top by the repository's (`nameFor`, `srcFolder`). Two skills a probe names alike are listed once (`unhiddenFirst`), so names that fell to `CTF`, `Strix` and nothing listed asdfgh1445/ctf-super-hub's 35 skills as 16 (tnt1223 on Discord, `TestSkillsNamedInAnotherScriptAllListed`). It comes from GitHub, from any other git repository, from a folder on this machine (linked, so editing the folder edits the skill) or from the market. A git repository (`kind: git`, sunset on Discord: GitLab, a company's own GitLab) is any https, http, ssh or `file://` address, `git@host:group/repo.git`, a bare `host.name/group/repo`, or a GitLab or Gitea page of a folder (`/-/tree//`, `/-/blob/…`, `/src/branch/…`; a branch with a `/` in its name is read as its first segment) (`gitSource`). It is fetched by the user's own `git` (`proc.FindTool`), so their credential helpers and SSH keys reach an intranet host: `git init`, then `fetch --depth 1 --no-tags -- ` and `checkout FETCH_HEAD` into a `magpie-skill-*` folder, then its `.git` is removed (`fetchGit`). What the user typed is data: an address starting with `-` and a `transport::` address (`ext::`, `fd::`, `file::`) are refused before git runs, the address follows `--`, git runs with `protocol.ext.allow=never` and `core.symlinks=false`, no shell, `GIT_TERMINAL_PROMPT=0` and (unless the user set an SSH command) `ssh -o BatchMode=yes`, so a sign-in it can't make fails instead of waiting. An address with a password or token in it is refused: library.json is shown and backed up. Git missing, a sign-in refused, a host key unknown, a branch missing and a host unreachable each say so (`gitError`; `TestGitSourceReads`, `TestInstallFromGitRepo`, `TestGitTreeURLInstallsFolder`, `TestGitMissingSaysSo`, `TestGitSignInRefusedSaysSo`, `TestGitRefusesOptionsAndTransports`, `TestGitErrorsSaid`). Each agent gets a link or a marked copy (#896, `SkillHow`). An agent in a WSL distro always gets a copy. A copy's mark keeps the hash of what was copied, so a sync knows a copy unchanged since then is current without reading its files (`copyIsFresh`, #1031); other copies are hashed. A skill an agent has of its own (`foundSkills`, the page's "In your agents") is brought in with `ImportSkill`, or taken out of every agent that has it with `RemoveFoundSkill` (#1303): its folders and copies of the very same files, its shared `~/.agents/skills` entry and a folder of it in the library's own folder go to the backups, its links are taken away, and a folder elsewhere it only links to, or another skill by that name, stays. Several go at once with `RemoveFoundSkills` (`POST /api/library/skills/remove-found-some`, wongxy on Discord): the "In your agents" heading's own Select picks them, and Remove… asks once, naming the count, before one change takes each out as `RemoveFoundSkill` would. A name that can't be taken out is left as it was, in `Result.Unremoved`, and stays picked with its error in its row's place (`foundErrs`); when none can go the change fails and nothing is touched. This Select and the library's are never on together: while one is on the other is dimmed, saying why, so neither click takes the other's bar away from above the pointer (`TestRemoveFoundSkills`, `found-skill-pick-remove.test.cjs`). A repository is fetched as one tarball of at most `maxFetch` (200 MB); a bigger one is fetched file by file from its tree (`fetchSkillFiles`), only as far as the caller reads: a link to a folder and an update ask GitHub for that folder's own list (`treeUnder`, git's `ref:path`; the whole list when that fails), the market fetches only the skills whose folder is the one it installs (#2794, sickn33/agentic-awesome-skills' 8,589 skills are 287 MB together), and a fetcher keeps such a part apart from another skill's of the same repository, which would otherwise read as removed (`fetcher.get`, `TestMarketSkillFromAHugeRepository`). GitHub's list is read up to `maxTree` (64 MB; that repository's is 11 MB) and an answer over the cap a caller gives `apiGet`, or one cut off, is an error saying so, never a body cut short for JSON to trip on (ye4241's `TestRepoTreeBigList`, `TestApiGetWholeAnswer`); a list GitHub truncated itself is too big (`TestTruncatedListIsTooBig`). And a skill over 200 MB on its own is left out rather than failing the rest: the probe lists the others and names it in `Probe.Left`, under the list in the page and in the TUI's flash. Only when every skill is too big does the fetch fail (#2062, mikubaka88/CCFA-Skills' 297 MB ccf-paper-writer; `TestOneSkillTooBigLeavesTheOthers`, `skill-too-big.test.cjs`). A probe keeps its download for the install from it for 15 minutes (`keepProbe`, `probeLife`), and removes it when it is probed again or that time is up, not at the next probe, which may never come. A download a magpie that quit left in the temp dir goes at the next probe once it is an hour old (`sweepStaleDownloads`). The package's TestMain gives the tests a temp dir of their own and fails a run that leaves a `magpie-skill-*` in it (#2321, `TestProbeDownloadEndsWithIt`, `TestStaleDownloadsSwept`). | [`skilltree.go`](../../internal/library/skilltree.go), [`skills.go`](../../internal/library/skills.go), [`skillgit.go`](../../internal/library/skillgit.go), [`skill_how.go`](../../internal/library/skill_how.go), [`skill_edits.go`](../../internal/library/skill_edits.go), [`skill_from.go`](../../internal/library/skill_from.go) | | Skills market | `MarketSkills` lists skills.sh's most installed and what its search finds. magpie's own skills (`featuredSkills`), in [magpie-community/plugins](https://github.com/magpie-community/plugins/tree/main/skills), go first, marked official: `magpie-setup` has an agent set magpie up as the user asks through its commands (providers, accounts, agents, routing groups and rules, gateway keys and limits, models, the library), and `magpie-quota` lets an agent read `magpie quota --json` and wait with `magpie quota wait`. Their commands live in magpie's CLI, so a change to a command either uses gets the skill updated in that repository. Until skills.sh lists one it has no count of installs and no skills.sh link (`featured`). `InstallMarketSkill` installs any of them from its repository. | [`market.go`](../../internal/library/market.go) | | Skills a repository added | A check for updates (`CheckSkills`) also asks, for each GitHub repository and ref the library has skills from, GitHub's list of its files (`repoTree`, one API request, free when the ETag still matches). Only when that list has a skill folder beside the installed ones (under `newBase`, their deepest common folder) that the library doesn't have and hasn't offered does `findNew` fetch the repository for the skills' names and descriptions. `SeenSkills` records per `repo@ref` the paths the install picker showed and the ones set aside, so they aren't offered again. The finds live in memory (`newFound`) and reach the page as `View.NewSkills`; `AddNewSkills` gives each to the agents that have its repository's other skills, and `IgnoreNewSkills` sets it aside (`/api/library/skills/{add-new,ignore-new}`). | [`skillnew.go`](../../internal/library/skillnew.go), [`skillcheck.go`](../../internal/library/skillcheck.go) | diff --git a/internal/library/market.go b/internal/library/market.go index 53ff62883..b5c21ca5d 100644 --- a/internal/library/market.go +++ b/internal/library/market.go @@ -239,7 +239,8 @@ var seenServers = struct { // that match it, then the registry's. A search that is an address — a // repository, a page, an endpoint, a package — finds the ones at it. func MarketServers(q string) ([]MarketServer, error) { - q = strings.ToLower(strings.TrimSpace(q)) + raw := strings.TrimSpace(q) + q = strings.ToLower(raw) addr := address(q) var out []MarketServer for _, m := range featured { @@ -257,9 +258,9 @@ func MarketServers(q string) ([]MarketServer, error) { if q != "" { var found []MarketServer if addr != "" { - found, err = searchRegistryAt(addr) + found, err = searchAt(raw, addr) } else { - found, err = searchRegistry(q) + found, err = searchWords(q) } for _, f := range found { if !slices.ContainsFunc(out, func(m MarketServer) bool { return serverKey(&m.server) == serverKey(&f.server) }) { diff --git a/internal/library/market_repo.go b/internal/library/market_repo.go new file mode 100644 index 000000000..ee9505be3 --- /dev/null +++ b/internal/library/market_repo.go @@ -0,0 +1,386 @@ +package library + +import ( + "bufio" + "bytes" + "encoding/json" + "net/url" + "regexp" + "slices" + "strings" + + "github.com/pelletier/go-toml/v2" +) + +// A server the MCP Registry doesn't list can still be at the address +// searched for: a Python one in a repository's folder, as +// https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_askecho_search_infinity +// (CyberCaius on Discord), or a package on PyPI. Its pyproject.toml says +// the program it installs, and its README the environment it reads, so it +// is offered filled in: uvx --from git+https://github.com/o/r#subdirectory=p +// , with the README's keys to fill in. + +// repoAt is a folder of a GitHub repository a search names. +type repoAt struct { + Repo string // owner/name, as written + Ref string // "" for the default branch + Path string // the folder, "" for the top +} + +var ghRepoRe = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9_.-]+$`) + +// parseRepoAt reads a GitHub address as a repository's folder: +// github.com/o/r, with #subdirectory=p (pip's and uv's way), /tree/ref/p, +// /blob/ref/p/file, or git+https://github.com/o/r@ref; the case kept. +func parseRepoAt(q string) (repoAt, bool) { + q = strings.TrimSpace(q) + q = strings.TrimPrefix(q, "git+") + frag := "" + if i := strings.Index(q, "#"); i >= 0 { + q, frag = q[:i], q[i+1:] + } + if i := strings.Index(q, "?"); i >= 0 { + q = q[:i] + } + for _, p := range []string{"https://", "http://", "ssh://git@", "git@"} { + q = strings.TrimPrefix(q, p) + } + q = strings.TrimPrefix(q, "www.") + host, rest, ok := strings.Cut(q, "/") + if host == "github.com:" || strings.HasPrefix(host, "github.com:") { // git@github.com:o/r + host, rest, ok = "github.com", strings.TrimPrefix(q, "github.com:"), true + } + if !ok || !strings.EqualFold(host, "github.com") { + return repoAt{}, false + } + parts := strings.Split(strings.Trim(rest, "/"), "/") + if len(parts) < 2 { + return repoAt{}, false + } + var a repoAt + name := strings.TrimSuffix(parts[1], ".git") + if n, ref, found := strings.Cut(name, "@"); found { + name, a.Ref = strings.TrimSuffix(n, ".git"), ref + } + a.Repo = parts[0] + "/" + name + if !ghRepoRe.MatchString(a.Repo) { + return repoAt{}, false + } + if len(parts) >= 4 && (parts[2] == "tree" || parts[2] == "blob") { + a.Ref = parts[3] + sub := parts[4:] + if parts[2] == "blob" && len(sub) > 0 { + sub = sub[:len(sub)-1] // the file's folder + } + a.Path = strings.Join(sub, "/") + } + if vals, err := url.ParseQuery(frag); err == nil && vals.Get("subdirectory") != "" { + a.Path = vals.Get("subdirectory") + } + a.Path = strings.Trim(a.Path, "/") + if strings.Contains(a.Path, "..") { + return repoAt{}, false + } + return a, true +} + +// gitURL is the repository's folder as uv installs from it. +func (a repoAt) gitURL() string { + u := "git+https://github.com/" + a.Repo + if a.Ref != "" { + u += "@" + a.Ref + } + if a.Path != "" { + u += "#subdirectory=" + a.Path + } + return u +} + +func (a repoAt) file(name string) string { + if a.Path == "" { + return name + } + return a.Path + "/" + name +} + +type pyProject struct { + Project struct { + Name string `toml:"name"` + Description string `toml:"description"` + Scripts map[string]string `toml:"scripts"` + } `toml:"project"` +} + +// program is the one a project installs that runs its server: the only +// one, the one named as the project, or the one that says mcp. +func (p *pyProject) program() string { + names := slices.Sorted(func(yield func(string) bool) { + for k := range p.Project.Scripts { + if !yield(k) { + return + } + } + }) + switch { + case len(names) == 0: + return "" + case len(names) == 1: + return names[0] + case slices.Contains(names, p.Project.Name): + return p.Project.Name + } + for _, n := range names { + if strings.Contains(strings.ToLower(n), "mcp") { + return n + } + } + return names[0] +} + +// fromRepo is the Python server in a repository's folder, from its +// pyproject.toml and README; false when the folder has no project with a +// program to run. +func fromRepo(a repoAt) (MarketServer, bool) { + b, err := get(rawURL(a.Repo, a.Ref, a.file("pyproject.toml")), "text/plain", 1<<20) + if err != nil { + return MarketServer{}, false + } + var p pyProject + if toml.Unmarshal(b, &p) != nil { + return MarketServer{}, false + } + prog := p.program() + if prog == "" { + return MarketServer{}, false + } + readme, _ := get(rawURL(a.Repo, a.Ref, a.file("README.md")), "text/plain", 2<<20) + owner, _, _ := strings.Cut(a.Repo, "/") + home := "https://github.com/" + a.Repo + if a.Path != "" { + ref := a.Ref + if ref == "" { + ref = "HEAD" + } + home += "/tree/" + ref + "/" + a.Path + } + name := p.Project.Name + if name == "" { + name = prog + } + m := MarketServer{ID: "github.com/" + a.Repo + pathPart(a), Name: shortName(name), Title: name, Description: p.Project.Description, + Publisher: owner, Icon: gh(owner), Homepage: home, Transport: "stdio", Runs: "uvx", Match: true, + Inputs: envInputs(readme)} + m.server = Server{Name: m.Name, Transport: "stdio", Command: "uvx", Args: []string{"--from", a.gitURL(), prog}} + return m, true +} + +func pathPart(a repoAt) string { + s := "" + if a.Ref != "" { + s += "@" + a.Ref + } + if a.Path != "" { + s += "#subdirectory=" + a.Path + } + return s +} + +// pypiURL is PyPI's JSON API; a variable for tests. +var pypiURL = "https://pypi.org/pypi" + +var pypiNameRe = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]*$`) + +// fromPyPI is the server a PyPI package of that name runs, uvx , +// with what its description (its README) says it reads from the +// environment; false when PyPI has no such package. +func fromPyPI(name string) (MarketServer, bool) { + if !pypiNameRe.MatchString(name) { + return MarketServer{}, false + } + var body struct { + Info struct { + Name string `json:"name"` + Summary string `json:"summary"` + Description string `json:"description"` + HomePage string `json:"home_page"` + ProjectURLs map[string]string `json:"project_urls"` + } `json:"info"` + } + if getJSON(pypiURL+"/"+url.PathEscape(name)+"/json", &body) != nil || body.Info.Name == "" { + return MarketServer{}, false + } + i := body.Info + home := i.HomePage + for _, k := range []string{"Repository", "Source", "Homepage", "Source Code", "Code"} { + if home == "" && i.ProjectURLs[k] != "" { + home = i.ProjectURLs[k] + } + } + if home == "" { + home = "https://pypi.org/project/" + i.Name + "/" + } + m := MarketServer{ID: "pypi.org/project/" + strings.ToLower(i.Name), Name: shortName(i.Name), Title: i.Name, Description: i.Summary, + Homepage: home, Transport: "stdio", Runs: "uvx", Match: true, Inputs: envInputs([]byte(i.Description))} + if o := githubOwner(home); o != "" { + m.Publisher, m.Icon = o, gh(o) + } + m.server = Server{Name: m.Name, Transport: "stdio", Command: "uvx", Args: []string{i.Name}} + m.addrs = addrsOf(i.Name, "pypi.org/project/"+i.Name) + return m, true +} + +var ( + envBlockRe = regexp.MustCompile(`"env"\s*:\s*\{`) + envKeyRe = regexp.MustCompile(`^[A-Z][A-Z0-9_]*$`) + secretRe = regexp.MustCompile(`KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|AUTH`) + fenceRe = regexp.MustCompile("^\\s*(```|~~~)") +) + +// envInputs are the environment variables a README's configuration +// examples give the server ("env": {…} in an mcpServers block), in the +// order it gives them. Each says what the README's prose says about it. +// One alone is required; of several none is, since a README often has +// the user pick one way to sign in of two (an API key, or an access key +// and secret). +func envInputs(readme []byte) []Input { + var keys []string + vals := map[string]string{} + for _, loc := range envBlockRe.FindAllIndex(readme, -1) { + dec := json.NewDecoder(bytes.NewReader(readme[loc[1]-1:])) + var raw json.RawMessage + if dec.Decode(&raw) != nil { + continue + } + td := json.NewDecoder(bytes.NewReader(raw)) + if _, err := td.Token(); err != nil { // { + continue + } + for td.More() { + k, err := td.Token() + if err != nil { + break + } + var v any + if td.Decode(&v) != nil { + break + } + key, _ := k.(string) + if !envKeyRe.MatchString(key) || slices.Contains(keys, key) { + continue + } + keys = append(keys, key) + if s, ok := v.(string); ok { + vals[key] = s + } + } + } + about := proseAbout(readme, keys) + ins := []Input{} + for _, k := range keys { + in := Input{Key: k, Where: "env", Label: k, Description: about[k], Secret: secretRe.MatchString(k), Required: len(keys) == 1} + if v := vals[k]; v != "" && !in.Secret && !placeholderRe.MatchString(v) && !strings.ContainsAny(v, "<>") && !strings.HasPrefix(strings.ToLower(v), "your") { + in.Placeholder = v + } + ins = append(ins, in) + } + return ins +} + +// proseAbout is, for each key, the first line outside a code block of the +// README that names it, cut short. +func proseAbout(readme []byte, keys []string) map[string]string { + out := map[string]string{} + in := false + sc := bufio.NewScanner(bytes.NewReader(readme)) + sc.Buffer(make([]byte, 64<<10), 1<<20) + for sc.Scan() { + line := sc.Text() + if fenceRe.MatchString(line) { + in = !in + continue + } + if in { + continue + } + for _, k := range keys { + if out[k] == "" && strings.Contains(line, k) { + t := strings.TrimSpace(strings.TrimLeft(strings.TrimSpace(line), "#-*>|")) + if r := []rune(t); len(r) > 200 { + t = string(r[:200]) + "…" + } + out[k] = t + } + } + } + return out +} + +// keep has a server found outside the registry installable by its id, as +// offer does the registry's. +func keep(m MarketServer) MarketServer { + seenServers.Lock() + defer seenServers.Unlock() + seenServers.m[m.ID] = m + return m +} + +func matched(list []MarketServer) bool { + return slices.ContainsFunc(list, func(m MarketServer) bool { return m.Match }) +} + +// searchAt finds the servers at an address. A repository's folder is read +// first, since the registry lists no server by its folder; a repository is +// read when nothing the registry lists is at it, and a PyPI page asks PyPI. +func searchAt(raw, addr string) ([]MarketServer, error) { + ra, isRepo := parseRepoAt(raw) + if isRepo && ra.Path != "" { + if m, ok := fromRepo(ra); ok { + return []MarketServer{keep(m)}, nil + } + } + found, err := searchRegistryAt(addr) + if matched(found) { + return found, err + } + var m MarketServer + ok := false + switch { + case isRepo: + m, ok = fromRepo(ra) + case strings.Contains(strings.ToLower(raw), "pypi.org/project/"): + m, ok = fromPyPI(lastPart(addr)) + } + if ok { + return append([]MarketServer{keep(m)}, found...), nil + } + return found, err +} + +// searchWords is the registry's search, and, for a search that could be a +// server's package on PyPI (one word naming mcp with a - _ or . in it, so +// not PyPI's mcp, the SDK), that package when the +// registry lists nothing by that name: the registry doesn't list every +// server PyPI has (mcp-server-askecho-search-infinity). +func searchWords(q string) ([]MarketServer, error) { + if !strings.Contains(q, "mcp") || !strings.ContainsAny(q, "-_.") || !pypiNameRe.MatchString(q) { + return searchRegistry(q) + } + type res struct { + m MarketServer + ok bool + } + ch := make(chan res, 1) + go func() { + m, ok := fromPyPI(q) + ch <- res{m, ok} + }() + found, err := searchRegistry(q) + p := <-ch + if !p.ok || slices.ContainsFunc(found, func(m MarketServer) bool { + return strings.EqualFold(packageOf(&m.server), p.m.Title) || m.Name == p.m.Name + }) { + return found, err + } + p.m.Match = false // a name, not an address + return append([]MarketServer{keep(p.m)}, found...), err +} diff --git a/internal/library/market_repo_test.go b/internal/library/market_repo_test.go new file mode 100644 index 000000000..f47dcf819 --- /dev/null +++ b/internal/library/market_repo_test.go @@ -0,0 +1,183 @@ +package library + +import ( + "net/http" + "net/http/httptest" + "os" + "slices" + "strings" + "sync/atomic" + "testing" +) + +const askechoDir = "server/mcp_server_askecho_search_infinity" + +// fakeSources stands in for raw.githubusercontent.com, PyPI and the MCP +// Registry, which lists none of what's asked; they hand out volcengine's +// real pyproject.toml, README.md and PyPI entry for the askecho server, +// kept in testdata as fetched on 2026-10-30. It counts the registry's +// searches. +func fakeSources(t *testing.T) *atomic.Int64 { + t.Helper() + file := func(n string) []byte { + b, err := os.ReadFile("testdata/askecho/" + n) + if err != nil { + t.Fatal(err) + } + return b + } + var searches atomic.Int64 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/registry": + searches.Add(1) + w.Write([]byte(`{"servers":[]}`)) + case "/raw/volcengine/mcp-server/HEAD/" + askechoDir + "/pyproject.toml", "/raw/volcengine/mcp-server/main/" + askechoDir + "/pyproject.toml": + w.Write(file("pyproject.toml")) + case "/raw/volcengine/mcp-server/HEAD/" + askechoDir + "/README.md", "/raw/volcengine/mcp-server/main/" + askechoDir + "/README.md": + w.Write(file("README.md")) + case "/pypi/mcp-server-askecho-search-infinity/json": + w.Write(file("pypi.json")) + default: + http.NotFound(w, r) + } + })) + t.Cleanup(srv.Close) + wasRaw, wasReg, wasPyPI := rawURL, registryURL, pypiURL + rawURL = func(repo, ref, path string) string { + if ref == "" { + ref = "HEAD" + } + return srv.URL + "/raw/" + repo + "/" + ref + "/" + path + } + registryURL, pypiURL = srv.URL+"/registry", srv.URL+"/pypi" + t.Cleanup(func() { rawURL, registryURL, pypiURL = wasRaw, wasReg, wasPyPI }) + return &searches +} + +func inputKeys(m MarketServer) (keys []string) { + for _, in := range m.Inputs { + keys = append(keys, in.Key) + } + return +} + +var askechoEnv = []string{"VOLCENGINE_ACCESS_KEY", "VOLCENGINE_SECRET_KEY", "ASK_ECHO_SEARCH_INFINITY_API_KEY"} + +// CyberCaius on Discord pasted +// https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_askecho_search_infinity +// into the Library's MCP search: the registry lists no server there, so +// the page offered only a blank command named "server". The folder's +// pyproject.toml names the program and its README the keys it reads, so +// the server is offered as uv runs it from GitHub, with the README's +// three keys to fill in (an API key, or an access key and secret: none +// of them required alone), and once installed reaches Claude Desktop. +func TestMarketServerInRepoFolder(t *testing.T) { + h := sandbox(t) + p, _ := desktopFiles(t, h) + write(t, p, `{"mcpServers": {}}`) + searches := fakeSources(t) + + q := "https://github.com/volcengine/mcp-server#subdirectory=" + askechoDir + list, err := MarketServers(q) + if err != nil || len(list) == 0 { + t.Fatalf("%s: %v %v", q, list, err) + } + m := list[0] + wantArgs := []string{"--from", "git+https://github.com/volcengine/mcp-server#subdirectory=" + askechoDir, "mcp-server-askecho-search-infinity"} + if !m.Match || m.server.Command != "uvx" || !slices.Equal(m.server.Args, wantArgs) || m.Name != "askecho-search-infinity" || m.Runs != "uvx" { + t.Fatalf("offered %+v (%v %v)", m, m.server.Command, m.server.Args) + } + if !slices.Equal(inputKeys(m), askechoEnv) { + t.Fatalf("inputs %v", inputKeys(m)) + } + for _, in := range m.Inputs { + if in.Where != "env" || !in.Secret || in.Required { + t.Errorf("input %+v", in) + } + } + if d := m.Inputs[2].Description; !strings.Contains(d, "二选一") { + t.Errorf("the API key's description: %q", d) + } + if searches.Load() != 0 { + t.Errorf("the registry was searched %d times for a folder it can't list", searches.Load()) + } + if c := CustomAt(q, list); c != nil { + t.Errorf("a blank server offered beside it: %+v", c) + } + + // installed with only the API key, it goes to Claude Desktop as uv + // runs it, with that key alone in its environment + ok(t)(InstallServer(m.ID, map[string]string{"ASK_ECHO_SEARCH_INFINITY_API_KEY": "k-1"}, []string{"claude-desktop"})) + got := desktopServers(t, p)[m.Name] + if got["command"] != "uvx" || !slices.Equal(strList(got["args"]), wantArgs) { + t.Fatalf("Claude Desktop's entry: %v", got) + } + if env, _ := got["env"].(map[string]any); len(env) != 1 || env["ASK_ECHO_SEARCH_INFINITY_API_KEY"] != "k-1" { + t.Errorf("Claude Desktop's env: %v", got["env"]) + } + // and the search says the library has it + if list, _ = MarketServers(q); len(list) == 0 || list[0].Have != m.Name { + t.Errorf("searched again: %+v", list) + } +} + +// The folder's page on GitHub (…/tree/main/server/…) and a file in it +// are the same folder, at that branch. +func TestMarketServerRepoFolderPage(t *testing.T) { + sandbox(t) + fakeSources(t) + for _, q := range []string{ + "https://github.com/volcengine/mcp-server/tree/main/" + askechoDir, + "github.com/volcengine/mcp-server/blob/main/" + askechoDir + "/README.md", + } { + list, _ := MarketServers(q) + if len(list) == 0 || list[0].server.Args[1] != "git+https://github.com/volcengine/mcp-server@main#subdirectory="+askechoDir { + t.Errorf("%s: %+v", q, list) + } + } +} + +// Searched for by its PyPI name, which the registry doesn't list, it is +// offered as uvx runs the package, with the keys its description gives. +func TestMarketServerOnPyPI(t *testing.T) { + sandbox(t) + fakeSources(t) + for _, q := range []string{"mcp-server-askecho-search-infinity", "https://pypi.org/project/mcp-server-askecho-search-infinity/"} { + list, _ := MarketServers(q) + if len(list) == 0 || list[0].server.Command != "uvx" || !slices.Equal(list[0].server.Args, []string{"mcp-server-askecho-search-infinity"}) || + !slices.Equal(inputKeys(list[0]), askechoEnv) { + t.Fatalf("%s: %+v", q, list) + } + if c := CustomAt(q, list); strings.HasPrefix(q, "https://") && c != nil { + t.Errorf("%s: a blank server offered beside it: %+v", q, c) + } + } +} + +func TestParseRepoAt(t *testing.T) { + for q, want := range map[string]repoAt{ + "https://github.com/volcengine/mcp-server#subdirectory=server/x": {Repo: "volcengine/mcp-server", Path: "server/x"}, + "git+https://github.com/o/R.git@v1#egg=x&subdirectory=a/b/": {Repo: "o/R", Ref: "v1", Path: "a/b"}, + "github.com/o/r/tree/dev/src/Srv": {Repo: "o/r", Ref: "dev", Path: "src/Srv"}, + "git@github.com:o/r.git": {Repo: "o/r"}, + "https://www.github.com/o/r/": {Repo: "o/r"}, + } { + if got, ok := parseRepoAt(q); !ok || got != want { + t.Errorf("%s: %+v %v", q, got, ok) + } + } + for _, q := range []string{"https://gitlab.com/o/r", "github.com/o", "o/r", "https://github.com/o/r#subdirectory=../x"} { + if got, ok := parseRepoAt(q); ok { + t.Errorf("%s read as %+v", q, got) + } + } +} + +// One key a README gives is required; a placeholder value is no hint. +func TestEnvInputsOne(t *testing.T) { + ins := envInputs([]byte("Set `FOO_TOKEN` first.\n```json\n{\"mcpServers\":{\"x\":{\"command\":\"uvx\",\"env\":{\"FOO_TOKEN\":\"\",\"lower\":\"x\"}}}}\n```\n")) + if len(ins) != 1 || !ins[0].Required || !ins[0].Secret || ins[0].Placeholder != "" || ins[0].Description != "Set `FOO_TOKEN` first." { + t.Fatalf("%+v", ins) + } +} diff --git a/internal/library/testdata/askecho/README.md b/internal/library/testdata/askecho/README.md new file mode 100644 index 000000000..486ff52ab --- /dev/null +++ b/internal/library/testdata/askecho/README.md @@ -0,0 +1,177 @@ +# 联网搜索API MCP Server +## 版本信息 +v0.2.0 +## 产品描述 +火山引擎联网搜索API,提供豆包搜索 Custom 版网页与基础图片搜索能力,帮助大模型获取更准确、更新鲜的外部信息。 +## 分类 +火山引擎云原生 +## 标签 +- 搜索工具 +- 知识获取 + +## Tools +本 MCP Server 产品提供以下 Tools (工具/能力): +### Tool 1: web_search + +#### 类型 +saas +#### 详细描述 +根据用户输入问题,返回联网搜索结果,支持网页与基础图片搜索。 +#### 调试所需的输入参数: +输入: +```json +{ + "inputSchema": { + "type": "object", + "required": [ + "Query" + ], + "properties": { + "Query": { + "description": "用户搜索 query,1~100 个字符", + "type": "string" + }, + "Count": { + "description": "返回条数;web 默认 10 条、最多 50 条,image 默认且最多 5 条", + "type": "number" + }, + "SearchType": { + "description": "搜索类型,仅支持 web 或 image,默认 web", + "type": "string" + }, + "TimeRange": { + "description": "web 搜索时间范围,可选 OneDay/OneWeek/OneMonth/OneYear 或 YYYY-MM-DD..YYYY-MM-DD", + "type": "string" + }, + "AuthLevel": { + "description": "权威等级过滤,0 为默认,1 为非常权威", + "type": "number" + }, + "NeedContent": { + "description": "是否返回网页正文,仅支持 web", + "type": "boolean" + }, + "NeedUrl": { + "description": "是否返回网页 URL,仅支持 web", + "type": "boolean" + }, + "Sites": { + "description": "仅搜索指定站点,以 | 分隔,最多 20 个,仅支持 web", + "type": "string" + }, + "BlockHosts": { + "description": "排除指定站点,以 | 分隔,最多 5 个,仅支持 web", + "type": "string" + }, + "Industry": { + "description": "行业搜索,可选 finance、game 或 gov,仅支持 web", + "type": "string" + }, + "QueryRewrite": { + "description": "是否启用查询改写", + "type": "boolean" + }, + "ContentFormats": { + "description": "网页正文格式,可选 text 或 markdown,仅支持 web", + "type": "string" + } + } + }, + "name": "web_search", + "description": "联网搜索 API 调用" +} +``` +输出: +```json +联网搜索结果,结构参考官方 API 文档 https://www.volcengine.com/docs/87772/2272953 +``` + +#### 最容易被唤起的 Prompt示例 +联网搜索北京周边游攻略 +## 可适配平台 +Claude Code, Codex, Trae,Cursor等支持MCP协议的AI工具 +## 服务开通链接 (整体产品) +登录火山控制台,开通【联网搜索API】,服务开通链接:https://console.volcengine.com/search-infinity/web-search + +API Key 创建链接:https://console.volcengine.com/search-infinity/api-key +## 鉴权方式 +- API Key鉴权 +- 火山引擎的AKSK鉴权体系 +## 安装部署 +### 前置准备 +- Python 3.12 / 3.13 +- UV + **Linux/macOS:** +```bash +curl -LsSf https://astral.sh/uv/install.sh | sh +``` +**Windows:** +```bash +powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" +``` +### 安装 +克隆仓库: +```bash +git clone git@github.com:volcengine/mcp-server.git +``` +### 使用方法 +启动服务器: +**UV** +```bash +cd mcp-server/server/mcp_server_askecho_search_infinity +uv run mcp-server-askecho-search-infinity +# 使用sse/streamable-http模式启动(默认为stdio) +uv run mcp-server-askecho-search-infinity -t sse +uv run mcp-server-askecho-search-infinity -t streamable-http +``` +## 部署 +### UVX +鉴权信息,火山引擎 AK/SK 与 `ASK_ECHO_SEARCH_INFINITY_API_KEY` 二选一即可 + +#### 推荐:从 PyPI 或已配置的火山镜像源安装 + +该方式不依赖 GitHub,`>=0.2.0` 会自动使用可获取的最新发布版本。 + +```json +{ + "mcpServers": { + "mcp-server-askecho-search-infinity": { + "command": "uvx", + "args": [ + "--from", + "mcp-server-askecho-search-infinity>=0.2.0", + "mcp-server-askecho-search-infinity" + ], + "env": { + "VOLCENGINE_ACCESS_KEY": "", + "VOLCENGINE_SECRET_KEY": "", + "ASK_ECHO_SEARCH_INFINITY_API_KEY": "" + } + } + } +} +``` + +#### 备用:从 GitHub 源码安装 + +```json +{ + "mcpServers": { + "mcp-server-askecho-search-infinity": { + "command": "uvx", + "args": [ + "--from", + "git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_askecho_search_infinity", + "mcp-server-askecho-search-infinity" + ], + "env": { + "VOLCENGINE_ACCESS_KEY": "", + "VOLCENGINE_SECRET_KEY": "", + "ASK_ECHO_SEARCH_INFINITY_API_KEY": "" + } + } + } +} +``` +## License +volcengine/mcp-server is licensed under the [MIT License](https://github.com/volcengine/mcp-server/blob/main/LICENSE) diff --git a/internal/library/testdata/askecho/pypi.json b/internal/library/testdata/askecho/pypi.json new file mode 100644 index 000000000..f9805bfff --- /dev/null +++ b/internal/library/testdata/askecho/pypi.json @@ -0,0 +1,10 @@ +{ + "info": { + "name": "mcp-server-askecho-search-infinity", + "summary": "Web Search API MCP Server", + "version": "0.2.0", + "project_urls": null, + "description": "# 联网搜索API MCP Server\n## 版本信息\nv0.2.0\n## 产品描述\n火山引擎联网搜索API,提供豆包搜索 Custom 版网页与基础图片搜索能力,帮助大模型获取更准确、更新鲜的外部信息。\n## 分类\n火山引擎云原生\n## 标签\n- 搜索工具\n- 知识获取\n\n## Tools\n本 MCP Server 产品提供以下 Tools (工具/能力):\n### Tool 1: web_search\n\n#### 类型\nsaas\n#### 详细描述\n根据用户输入问题,返回联网搜索结果,支持网页与基础图片搜索。\n#### 调试所需的输入参数:\n输入:\n```json\n{\n \"inputSchema\": {\n \"type\": \"object\",\n \"required\": [\n \"Query\"\n ],\n \"properties\": {\n \"Query\": {\n \"description\": \"用户搜索 query,1~100 个字符\",\n \"type\": \"string\"\n },\n \"Count\": {\n \"description\": \"返回条数;web 默认 10 条、最多 50 条,image 默认且最多 5 条\",\n \"type\": \"number\"\n },\n \"SearchType\": {\n \"description\": \"搜索类型,仅支持 web 或 image,默认 web\",\n \"type\": \"string\"\n },\n \"TimeRange\": {\n \"description\": \"web 搜索时间范围,可选 OneDay/OneWeek/OneMonth/OneYear 或 YYYY-MM-DD..YYYY-MM-DD\",\n \"type\": \"string\"\n },\n \"AuthLevel\": {\n \"description\": \"权威等级过滤,0 为默认,1 为非常权威\",\n \"type\": \"number\"\n },\n \"NeedContent\": {\n \"description\": \"是否返回网页正文,仅支持 web\",\n \"type\": \"boolean\"\n },\n \"NeedUrl\": {\n \"description\": \"是否返回网页 URL,仅支持 web\",\n \"type\": \"boolean\"\n },\n \"Sites\": {\n \"description\": \"仅搜索指定站点,以 | 分隔,最多 20 个,仅支持 web\",\n \"type\": \"string\"\n },\n \"BlockHosts\": {\n \"description\": \"排除指定站点,以 | 分隔,最多 5 个,仅支持 web\",\n \"type\": \"string\"\n },\n \"Industry\": {\n \"description\": \"行业搜索,可选 finance、game 或 gov,仅支持 web\",\n \"type\": \"string\"\n },\n \"QueryRewrite\": {\n \"description\": \"是否启用查询改写\",\n \"type\": \"boolean\"\n },\n \"ContentFormats\": {\n \"description\": \"网页正文格式,可选 text 或 markdown,仅支持 web\",\n \"type\": \"string\"\n }\n }\n },\n \"name\": \"web_search\",\n \"description\": \"联网搜索 API 调用\"\n}\n```\n输出:\n```json\n联网搜索结果,结构参考官方 API 文档 https://www.volcengine.com/docs/87772/2272953\n```\n\n#### 最容易被唤起的 Prompt示例\n联网搜索北京周边游攻略\n## 可适配平台\nClaude Code, Codex, Trae,Cursor等支持MCP协议的AI工具\n## 服务开通链接 (整体产品)\n登录火山控制台,开通【联网搜索API】,服务开通链接:https://console.volcengine.com/search-infinity/web-search\n\nAPI Key 创建链接:https://console.volcengine.com/search-infinity/api-key\n## 鉴权方式\n- API Key鉴权\n- 火山引擎的AKSK鉴权体系\n## 安装部署\n### 前置准备\n- Python 3.12 / 3.13\n- UV\n **Linux/macOS:**\n```bash\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n```\n**Windows:**\n```bash\npowershell -ExecutionPolicy ByPass -c \"irm https://astral.sh/uv/install.ps1 | iex\"\n```\n### 安装\n克隆仓库:\n```bash\ngit clone git@github.com:volcengine/mcp-server.git\n```\n### 使用方法\n启动服务器:\n**UV**\n```bash\ncd mcp-server/server/mcp_server_askecho_search_infinity\nuv run mcp-server-askecho-search-infinity\n# 使用sse/streamable-http模式启动(默认为stdio)\nuv run mcp-server-askecho-search-infinity -t sse\nuv run mcp-server-askecho-search-infinity -t streamable-http\n```\n## 部署\n### UVX\n鉴权信息,火山引擎 AK/SK 与 `ASK_ECHO_SEARCH_INFINITY_API_KEY` 二选一即可\n\n#### 推荐:从 PyPI 或已配置的火山镜像源安装\n\n该方式不依赖 GitHub,`>=0.2.0` 会自动使用可获取的最新发布版本。\n\n```json\n{\n \"mcpServers\": {\n \"mcp-server-askecho-search-infinity\": {\n \"command\": \"uvx\",\n \"args\": [\n \"--from\",\n \"mcp-server-askecho-search-infinity>=0.2.0\",\n \"mcp-server-askecho-search-infinity\"\n ],\n \"env\": {\n \"VOLCENGINE_ACCESS_KEY\": \"\",\n \"VOLCENGINE_SECRET_KEY\": \"\",\n \"ASK_ECHO_SEARCH_INFINITY_API_KEY\": \"\"\n }\n }\n }\n}\n```\n\n#### 备用:从 GitHub 源码安装\n\n```json\n{\n \"mcpServers\": {\n \"mcp-server-askecho-search-infinity\": {\n \"command\": \"uvx\",\n \"args\": [\n \"--from\",\n \"git+https://github.com/volcengine/mcp-server#subdirectory=server/mcp_server_askecho_search_infinity\",\n \"mcp-server-askecho-search-infinity\"\n ],\n \"env\": {\n \"VOLCENGINE_ACCESS_KEY\": \"\",\n \"VOLCENGINE_SECRET_KEY\": \"\",\n \"ASK_ECHO_SEARCH_INFINITY_API_KEY\": \"\"\n }\n }\n }\n}\n```\n## License\nvolcengine/mcp-server is licensed under the [MIT License](https://github.com/volcengine/mcp-server/blob/main/LICENSE)\n", + "description_content_type": "text/markdown" + } +} \ No newline at end of file diff --git a/internal/library/testdata/askecho/pyproject.toml b/internal/library/testdata/askecho/pyproject.toml new file mode 100644 index 000000000..0b34e2f0b --- /dev/null +++ b/internal/library/testdata/askecho/pyproject.toml @@ -0,0 +1,17 @@ +[project] +name = "mcp-server-askecho-search-infinity" +version = "0.2.0" +description = "Web Search API MCP Server" +readme = "README.md" +requires-python = ">=3.12,<3.14" +dependencies = [ + "mcp>=1.29.0,<2.0.0", + "aiohttp>=3.9.0", +] + +[project.scripts] +mcp-server-askecho-search-infinity = "mcp_server_askecho_search_infinity:main" + +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta"