library: a Python MCP server in a GitHub repository's folder is found and added filled in (CyberCaius on Discord)
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/<ref>/…, /blob/<ref>/…/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=<path> <program>, 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 <package> 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 onceef9e943(AnySearchd05482babin): ok; the push then rebased onto70a0c387c(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/mainceef9e943, 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.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -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) }) {
|
||||
|
||||
@@ -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
|
||||
// <program>, 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 <name>,
|
||||
// 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
|
||||
}
|
||||
@@ -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\":\"<your 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)
|
||||
}
|
||||
}
|
||||
+177
@@ -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)
|
||||
+10
File diff suppressed because one or more lines are too long
@@ -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"
|
||||
Reference in New Issue
Block a user