Sitelet https://github.com/arabold/docs-mcp-server/pull/477
Skip to content

feat(mcp): add include/exclude pattern support to scrape_docs - #477

Open
hjhriedel wants to merge 4 commits into
arabold:mainfrom
hjhriedel:feat/mcp-scrape-include-exclude-patterns
Open

feat(mcp): add include/exclude pattern support to scrape_docs#477
hjhriedel wants to merge 4 commits into
arabold:mainfrom
hjhriedel:feat/mcp-scrape-include-exclude-patterns

Conversation

@hjhriedel

Copy link
Copy Markdown

Adds includePatterns/excludePatterns support to the MCP scrape_docs tool.

Changes

src/mcp/mcpServer.ts (+32):

  • Exposes includePatterns and excludePatterns on the scrape_docs tool schema as comma-separated strings (regex patterns wrapped in slashes, e.g. /pattern/).
  • Strings are used instead of arrays so MCP client tool-call renderers (e.g. opencode TUI) display them inline — they silently drop array arguments.
  • splitPatterns() helper splits the comma-separated string into trimmed, non-empty string[] before passing to the scraper (which keeps receiving arrays as before).

The underlying scraper already supported these options; this PR exposes them through the MCP interface.

@arabold arabold left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good changes, thanks for this. My only concern is that this breaks comma in regex pattern. It might be an edge case but there are legitimate use cases for it:

  • Regex quantifiers: /\/v\d{1,3}\//
  • Glob brace expansion: **/*.{js,ts}
  • Literal commas in URLs

The CLI avoids it by accepting repeated --include-pattern / --exclude-pattern flags as arrays. I think the web UI suffers from the same problem as your logic here though.

I think the best option would be to use z.array(z.string()) for MCP. Something like this:

const patternsSchema = z.union([z.string(), z.array(z.string())]).transform((value) =>
  typeof value === "string" ? [value] : value,
);

Comment thread src/mcp/mcpServer.ts Outdated
function splitPatterns(patterns: string | undefined): string[] | undefined {
if (patterns === undefined) return undefined;
const items = patterns
.split(",")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we preserve commas inside a single regex? A pattern that uses a comma, such as a range, would be split into two pieces and stop working. Please split only between patterns, or support escaped commas.

@hjhriedel

Copy link
Copy Markdown
Author

Thanks — on top of your union proposal I went one step further, because MCP clients like the opencode TUI only render primitive arguments (arrays get dropped from the tool-call display), so the string form is what actually shows up for users.

New behavior:

  • String → split only on top-level commas: commas inside {}, [], or () are preserved, and , escapes a literal comma. So "/version-v0.3/, /versioned_docs/version-v0.3/" becomes two patterns, but //v\d{1,3}// and **/*.{js,ts} stay whole — exactly the cases you flagged.
  • Array → still accepted as exact multi-pattern input.

This keeps the string argument visible in the TUI and safe for regex/glob commas. Updated the schema description and added tests for quantifiers, brace expansion, character classes, escaped commas, and empty segments.

@arabold arabold left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the comma handling and covering the edge cases with tests.

@hjhriedel

hjhriedel commented Aug 25, 2026

Copy link
Copy Markdown
Author

Thanks for addressing the comma handling and covering the edge cases with tests.

Thank you for this awesome project!

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