Skip to content

feat(mcp): add optional SpecStream web search tool - #2477

Open
Specstreamai wants to merge 1 commit into
78:mainfrom
Specstreamai:feat/specstream-web-search
Open

Specstreamai wants to merge 1 commit into
78:mainfrom
Specstreamai:feat/specstream-web-search

Conversation

@Specstreamai

Copy link
Copy Markdown

This adds SpecStream as a third optional search tool, self.specstream.web_search, built the same way as the Firecrawl tool from #2468. Saving a key under Advanced → SpecStream on the provisioning page registers it, and clearing the key removes it. Devices without a SpecStream key see no change, and the Tavily and Firecrawl tools are untouched.

The tool sends one POST https://api.specstream.ai/v1/web-search with {"q": ..., "num": 3, "speed": "fast"} and a Bearer key. Fast mode returns the engines' results with their snippets in about a second, so it stays well inside the 8 second timeout. The reply goes through ReadJsonClipped under the same 16 KB ceiling, and data.sources is formatted by the shared FormatSearchResultItems, so the output is the same numbered title, URL and snippet text as the other tools.

Changes

  • main/mcp_tools.cc: self.specstream.web_search, registered at boot or when a key is saved (NVS key specstream_key, 14 characters). It reuses LoadApiKey, StoreApiKey and PostSearch.
  • main/mcp_tools.h: HasSpecStreamApiKey, SaveSpecStreamApiKey and the key length limit.
  • main/web_search_format.h: FormatSpecStreamSearchResults, which reads data.sources with snippet as the text field.
  • main/boards/common/portal_settings.cc: a SpecStream section with an API key field and zh-CN/zh-TW strings, saved through SaveApiKey.
  • docs/mcp-usage.md: the tool row and where to set the key.
  • scripts/tests/: registration when a key is saved, cleared or present at boot (the HTTP stub checks the URL, the Bearer header, q and speed in the body, and that the key never appears in the body), and SpecStream formatting with a parse error, an empty list and a snippet cut on a UTF-8 boundary.

How I tested it

  • python3 -m unittest scripts/tests/test_mcp_server.py scripts/tests/test_web_search_format.py: 37 tests pass, 3 of them new.
  • python3 -m unittest discover -s scripts/tests: everything else passes; the only errors are the 6 in test_ci_selection.py, which call python and my host only has python3.
  • clang-format 19 with the repo's .clang-format gives no changes on the added lines.
  • I have no ESP-IDF toolchain or board here, so the board builds in CI are the first firmware build of this change.

To try it: flash, open Advanced → SpecStream, paste a key from specstream.ai, save, and ask the device something current. New accounts get $2 of credit with no card, and a fast search is $1 per 1,000.

Disclosure: I work on SpecStream.

Saving a key under Advanced > SpecStream registers self.specstream.web_search, and clearing it removes the tool. The tool sends one fast search for three results to SpecStream's /v1/web-search and returns the same numbered title, URL and snippet text as the other search tools.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant