Files
plugins/packages/search1api/README.md
T
wang2 e0369f59ba search1api 0.1.3: Search1API as a web search API in Settings (#1219)
search1api 0.1.3 adds Search1API to magpie's Settings as a web search API. A search goes out as the Search1API account magpie picked (OAuth or API key, renewed before each search). The option key or SEARCH1API_API_KEY is used only when the host gives no account. A refusal (401, 402, 429) keeps its status and Retry-After, so magpie rests that account for search only. Results map title, url, snippet and date.

Thanks @fatwang2.

Run at the reviewed head d4bcb9da (mote, HOME=$(mktemp -d)):
- node --test tests/*.test.mjs: 27 pass.
- bun test: 27 pass.
- bun scripts/check.mjs search1api: ok.

Broken by hand: b54f3636c's src/index.ts with this head's tests fails the account-over-option-key test (3 pass, 1 fail). An earlier round with the main code made websearch.test fail 4 of 4.

Not run: tests/host.integration.mjs, or a real Search1API account.
2026-11-16 19:37:34 +08:00

219 lines
8.8 KiB
Markdown

# Search1API for Magpie
Search1API web search, news, agentic search, page retrieval, sitemap discovery,
and trending tools in [Magpie](https://usemagpie.ai/), with browser OAuth and
API key sign-in, plus Search1API as a web search API in Magpie's settings. The source lives in this community repository and is published as
`@magpie-community/tools-search1api`. It uses native fetch with no runtime
dependencies; request bodies and defaults match the original integration.
## Install
In Magpie, open **Plugins → Add plugin** and enter:
```text
@magpie-community/tools-search1api
```
Or use the terminal:
```sh
magpie plugin add @magpie-community/tools-search1api
```
The package includes its TypeScript source and an `index.mjs` entry. Magpie's
Bun host loads it directly; installation and community packaging need no build.
## Sign in
### OAuth (recommended)
Choose **Search1API → Sign in to Search1API** in the plugin's sign-in controls,
or run:
```sh
magpie plugin login search1api oauth
```
Magpie opens your browser. Sign in with your Search1API account and approve
access, then return to Magpie. The plugin uses a dynamically registered public
OAuth client, authorization code flow with PKCE S256, and a temporary loopback
callback. No client secret or Search1API CLI is required.
The client is registered once and saved, with its callback port, in
`search1api-oauth-client.json` next to `plugin-auth.json`; later sign-ins
reuse it. If that port is busy, or a sign-in with the saved client does not
finish, the plugin registers a new client. The authorization URL carries
`utm_source=magpie` and API requests send `User-Agent: search1api-magpie/<version>`,
so Search1API can tell sign-ups and usage that come from Magpie.
The browser must run on the same computer as Magpie. For a remote or container
installation, use an API key instead. The callback expires after five minutes.
Magpie saves access and refresh tokens in `plugin-auth.json` under its config
directory (`~/.config/magpie`, or `$XDG_CONFIG_HOME/magpie`) with file mode
`0600`. The plugin reads only its own `search1api` entry and saves refreshed
tokens through Magpie's `client.auth.set`; it does not maintain a second token
store. Tool calls refresh expiring tokens and retry once after an OAuth `401`.
Refreshes are serialized across simultaneous calls and Magpie processes.
Search1API appears as a sign-in entry with **no chat models**. It authenticates
the tools, not a model provider. One Search1API account is active at a time;
signing in again replaces it.
To remove the saved sign-in:
```sh
magpie plugin logout search1api
```
This removes the local credentials. It does not revoke an authorization at the
authorization server or remove API keys configured separately below.
### API key
Choose **Search1API API key** in the same sign-in controls, or run:
```sh
magpie plugin login search1api api
```
Magpie prompts privately for the key and saves it in its credential store.
Get a key at [s1.dev](https://s1.dev/?utm_source=magpie&utm_medium=readme).
For automated deployments, the plugin also accepts an `apiKey` plugin option
in Magpie's options editor, or `SEARCH1API_API_KEY` in the environment of the
Magpie process. Precedence: plugin option → environment → Magpie sign-in.
An option or environment key overrides a saved OAuth account. `SEARCH1API_KEY`
and the CLI's `s1 login` session are not read.
`baseUrl` is an optional API base URL for a compatible deployment or local
testing. It defaults to `https://api.search1api.com`. HTTPS is required, except
for loopback test servers. OAuth discovery uses that API's protected-resource
metadata and validates the issuer and endpoints.
## Connect your agent
In **Settings → Plugins**, copy the plugin tools MCP address, then add it to
your agent's MCP configuration. The default address is:
```text
http://127.0.0.1:3425/mcp/magpie/tools
```
For Claude Code:
```sh
claude mcp add --transport http magpie-tools \
http://127.0.0.1:3425/mcp/magpie/tools
```
Other agents use the same Streamable HTTP endpoint. Use the address Magpie
shows if the port or host differs. Remote calls require a Magpie gateway key;
this is separate from your Search1API credential.
Installing the plugin does not write your agent's MCP configuration or replace
its built-in search tool. Magpie exposes tools from all enabled tool plugins
on this endpoint.
## Tools
Magpie prefixes each tool with the plugin name. Use the names reported by
your Magpie tools endpoint.
- `search`: web search, engine selection, site filters, date range and native
pagination. Page selection works on engines that support it.
- `news`: news search with optional article content.
- `ask`: describe what to find; Search1API chooses engines and a time window
and returns ranked results. Each completed call costs **5 credits**. It
returns search results rather than a generated answer.
- `crawl`: retrieve readable page content.
- `sitemap`: discover site links.
- `trending`: GitHub or Hacker News trends.
- `send_feedback`: report a wrong or empty result, an unresolved error,
mismatched docs or a missing capability to the Search1API team, through
Search1API's `POST /feedback` API. It is free and needs a Search1API sign-in or API key. The report (message,
intent, category, request id and model) goes only to Search1API, which stores
it in its feedback inbox on [Agentback](https://agentback.app), a
third-party host, linked to your Search1API account.
Search tool parameters follow the existing OpenCode integration. Search and news
preserve optional `published_date` and per-result `metadata`; Ask preserves
`intent`, `source`, `relevance`, and `errors`. Attribute Grokipedia results as
“Powered by xAI”. Results are returned as JSON text.
Magpie gives tools a 55-second deadline. Cancellation is forwarded to fetch.
Automatic request retries are disabled to keep calls within that deadline; OAuth
authentication is retried once after refreshing. Other upstream errors return
to the calling agent.
## Web search for every model
The plugin also adds **Search1API** to Magpie's own web search APIs, in
**Settings → Models → Web search**, after the built-in ones. Magpie uses it
when a model can't search the web itself, and orders, switches off or mixes it
like any other search API there.
It takes no separate key: it searches as the Search1API account you signed in
to above (OAuth or API key), which Magpie renews before each search. An
`apiKey` option or `SEARCH1API_API_KEY` is not used here: a search always
goes out as the account Magpie picked, so a refusal rests that account. Each search
is a Search1API `search` call on Google with up to the number of results
Magpie asks for, without page content. A refused request (401, 402, 429)
keeps its status, so Magpie rests the account for search and asks the next
search API.
## Development
From this folder, on Node 24 or later (or Bun for the tests):
```sh
npm install --workspaces=false --ignore-scripts --package-lock=false
npm run lint
npm run typecheck
npm run build
npm test
npm pack --dry-run --ignore-scripts
```
The TypeScript build is a local verification artifact in `dist/`; the published
package contains the reviewed source. `lint` checks the entry syntax and runs
the strict TypeScript checks (including unused code and switch fallthrough).
From the repository root, run the same checks as community CI with a temporary
home, as documented in `.github/workflows/pr.yml`:
```sh
bun test
bun scripts/check.mjs
```
The fetch-stub tests replace every fetch with synthetic responses, covering
all six wire bodies, defaults, validation, safe errors, OAuth discovery,
refresh/retry limits and cancellation. Local loopback fixtures additionally
exercise PKCE browser callbacks, key precedence, concurrent refreshes and
logout without real accounts or paid API calls.
An optional integration test uses Magpie's actual Bun plugin host and the same
local fixture. It is outside the default test filename pattern:
```sh
MAGPIE_HOST_PATH=/path/to/magpie/internal/plugin/host.js \
MAGPIE_BUN_PATH=/path/to/bun npm run test:magpie
```
The migrated integration was verified against Magpie host revision
`261f482260da435ecfa35004649955a5a2f749e9`. Live-account OAuth consent still
requires manual verification on the machine running Magpie.
## Maintenance and license
Migrated from [Search1API for Magpie v0.1.0](https://github.com/superagents-lab/magpie-search1api/tree/v0.1.0),
commit `89b9cd5fd1c1c105d603768c14404873d697941f`, under MIT. The original
Search1API copyright and license are retained in `LICENSE`.
This replaces the external-package listing proposed in
[#340](https://github.com/magpie-community/plugins/pull/340). Source changes
are reviewed here and published by `@magpie-community` through this
repository's existing publishing workflow; see the root README. This package
does not publish from the original repository's release workflow.