Skip to content

feat(mcp): add file analysis, alerts, organizations, and threat feed tools#179

Closed
annextuckner wants to merge 4 commits into
mainfrom
tuckner/mcp-tools
Closed

feat(mcp): add file analysis, alerts, organizations, and threat feed tools#179
annextuckner wants to merge 4 commits into
mainfrom
tuckner/mcp-tools

Conversation

@annextuckner
Copy link
Copy Markdown
Contributor

What

Six new MCP tools on top of depscore, each following the lib/<tool>-tool.ts registration pattern:

  • organizations — list orgs the authenticated user belongs to
  • alerts — paginated org alerts with severity/category/artifact filters
  • threat_feed — paginated org threat feed (GET /v0/orgs/{slug}/threat-feed)
  • package_files — file tree for any package on a supported ecosystem
  • package_file_contents — read one published file by content hash
  • package_file_grep — regex search a single file by hash

Adds a process-wide LRU blob cache (default 64 MB, tunable via SOCKET_BLOB_CACHE_BYTES) so repeated reads/greps of the same hash skip the socketusercontent fetch across stateless HTTP requests.

Extends buildPurl with optional qualifiers, an openvsxvscode rewrite with auto-added repository_url, and a placeholder-version check that treats 1.0.0 as stale only for ecosystems where the model historically defaults to it (npm/pypi), not for ecosystems that genuinely publish 1.0.0 (chrome, openvsx).

Test

  • pnpm run test:node-test — 77 tests pass
  • New unit tests: blob.test.ts, files.test.ts, purl.test.ts

…tools

Six new MCP tools on top of `depscore`, each following main's
`lib/<tool>-tool.ts` registration pattern:

- `organizations` — list orgs the authenticated user belongs to
- `alerts` — paginated org alerts with severity/category/artifact filters
- `threat_feed` — paginated org threat feed (GET /v0/orgs/{slug}/threat-feed)
- `package_files` — file tree for any package on a supported ecosystem
- `package_file_contents` — read one published file by content hash
- `package_file_grep` — regex search a single file by hash

Adds a process-wide LRU blob cache (default 64 MB, tunable via
SOCKET_BLOB_CACHE_BYTES) so repeated reads/greps of the same hash skip
the socketusercontent fetch across stateless HTTP requests.

Extends `buildPurl` with optional qualifiers, an `openvsx` → `vscode`
rewrite with auto-added `repository_url`, and a placeholder-version
check that only treats `1.0.0` as stale for ecosystems where the model
historically defaults to it (npm/pypi) — not for ecosystems that
genuinely publish 1.0.0 (chrome, openvsx).
pnpm 11.x no longer reads the package.json "pnpm.overrides" field. Move
the five overrides not already in pnpm-workspace.yaml (@hono/node-server,
fast-uri, hono, zod, zod-to-json-schema) into its overrides: block and
drop the dead pnpm field. Refresh the lockfile for the
plugin-patch-format-guard hook's catalog deps.

Repoint three scripts (test, check, lint) off the stale
lib-stable/spawn/spawn export onto process/spawn/child, matching every
other script after the lib 6.0.3 restructure.
The lib 6.0.3 restructure dropped the bare "logger" subpath's
getDefaultLogger export; it now lives at logger/default. Repoint the
three mock-client entrypoints and two scripts. The scripts also move off
the bare "lib" name onto the lib-stable self-import alias, matching the
rest of scripts/.
# Conflicts:
#	lib/depscore-tool.ts
#	lib/purl.ts
#	package.json
#	pnpm-lock.yaml
#	scripts/check-versions.ts
#	scripts/lint.mts
John-David Dalton (jdalton) added a commit that referenced this pull request Jun 1, 2026
First seam of #179. buildPurl takes an optional qualifiers map, rewrites
the friendly `openvsx` ecosystem to PURL type `vscode` with an auto
`repository_url=https://open-vsx.org` qualifier (caller-overridable), and
only treats `1.0.0` as a placeholder version for npm/pypi (chrome/openvsx
publish real 1.0.0). Ported the PR's 5 new cases into test/purl.test.ts.

Co-authored-by: annextuckner <annextuckner@users.noreply.github.com>
John-David Dalton (jdalton) added a commit that referenced this pull request Jun 1, 2026
Second seam of #179. Adds a debug() that forwards to logger.info only
when SOCKET_DEBUG is set, preserving the pre-bundle pino behavior where
verbose request/cache traces stayed quiet by default — the new file/blob/
threat-feed tools use it. Also switches scripts/check-versions.ts to the
-stable logger import per the scripts/** self-import rule.

Co-authored-by: annextuckner <annextuckner@users.noreply.github.com>
John-David Dalton (jdalton) added a commit that referenced this pull request Jun 1, 2026
lib/blob.ts fetches single (Q) + chunked (S) blobs from socketusercontent,
decoding UTF-8 / flagging binary / honoring maxBytes. Converted off raw
fetch() onto httpRequest (arrayBuffer for binary bodies), null→undefined.
lib/blob-cache.ts is the process-wide LRU; its env reads now route through
new lib/env.ts getters (getSocketBlob*/getSocketBypass*). test/blob.test.ts
ports the PR's 10 cases to vitest, mocking socketusercontent with nock
(no live network). getOrFetchBlob cache coverage is a follow-up.

Co-authored-by: annextuckner <annextuckner@users.noreply.github.com>
John-David Dalton (jdalton) added a commit that referenced this pull request Jun 1, 2026
lib/files.ts fetches a package's file manifest (httpRequest, not fetch),
normalizes + renders it as a tree. lib/package-files-tool.ts registers
three read-only MCP tools — package_files (list), package_file_contents
(read via the blob cache), package_file_grep (regex search) — wired into
createConfiguredServer(). New lib/env.ts getter for the internal UA;
getStaticApiKey() exported from depscore-tool for the shared auth fallback.
test/files.test.ts ports the PR's 17 cases to vitest (pure helpers direct,
fetchFileList via nock). package_files-tool handler coverage is a follow-up.

Co-authored-by: annextuckner <annextuckner@users.noreply.github.com>
John-David Dalton (jdalton) added a commit that referenced this pull request Jun 1, 2026
Final seam of #179. Adds the org-scoped data modules + MCP tool wrappers:
- organizations — list the user's Socket orgs (discovers org_slug)
- alerts — latest org security alerts with severity/category/etc filters
- threat-feed — org threat-feed items (renamed threatFeed.ts → threat-feed.ts)
All three converted off raw fetch() onto httpRequest, errorMessage(e) for
catches, optional props explicit-undefined, and registered in
createConfiguredServer(). Tests (alerts/organizations/threat-feed) port the
query-builders direct + the fetch paths via nock. Tool-handler coverage is
a follow-up. Server smoke-creates with all tools registered.

Co-authored-by: annextuckner <annextuckner@users.noreply.github.com>
@jdalton
Copy link
Copy Markdown
Collaborator

Landed in main across five focused commits (you're credited as co-author on each):

  • 2bef630 feat(purl): openvsx/vscode rewrite + qualifiers in buildPurl
  • 2a8f1c6 feat(logger): SOCKET_DEBUG-gated debug() helper
  • 4e78661 feat(blob): content-addressed blob fetch + LRU cache
  • 728df12 feat(files): package_files / package_file_contents / package_file_grep tools
  • f4eab89 feat(tools): organizations / alerts / threat-feed tools

Adapted to current main rather than merged: every data module was converted off raw fetch() onto httpRequest from @socketsecurity/lib, lib/threatFeed.ts was renamed to lib/threat-feed.ts (kebab-case), tools register in createConfiguredServer(), and the node:test files were rewritten as vitest suites mocking the network with nock (the repo migrated to vitest). All four tools are registered and the server smoke-creates cleanly. Tool-handler (MCP wrapper) unit coverage is tracked as a follow-up; data-module + pure-helper coverage is complete. Thanks — this was a substantial, well-structured contribution.

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.

2 participants