Skip to content

feat: scope-aware tool registration (extends #136)#143

Open
Jack-Lewis1 wants to merge 2 commits intoXeroAPI:mainfrom
Jack-Lewis1:feat/scope-aware-tool-registration
Open

feat: scope-aware tool registration (extends #136)#143
Jack-Lewis1 wants to merge 2 commits intoXeroAPI:mainfrom
Jack-Lewis1:feat/scope-aware-tool-registration

Conversation

@Jack-Lewis1
Copy link
Copy Markdown

Relates to: #136 — configurable XERO_SCOPES for custom connections.

This branch extends that idea so reduced scopes don’t leave payroll (or other) tools registered while the token would 403 them.

What changed

Area Summary
src/helpers/scopes.ts Default scope string, VALID_SCOPES (warn on unknown, still sent to Xero), getConfiguredScopes() / getConfiguredScopeString(), ToolScopes groups for tools.
Tools Each CreateXeroTool(...) passes requiredScopes (via ToolScopes.*).
tool-factory.ts Registers a tool only if configured scopes include all requiredScopes when using client id/secret. Bearer token mode: no filtering (token scopes aren’t known here).
xero-client.ts Token request uses getConfiguredScopeString() (same source as gating).
src/index.ts import "dotenv/config" first so XERO_SCOPES is loaded before tool registration.
README Default scopes link to scopes.ts, scope↔tool table, granular-vs-broad scope caveat, XERO_MCP_LOG_SCOPE_FILTERING.
.env.example XERO_SCOPES, XERO_CLIENT_BEARER_TOKEN, optional logging var.

New / notable env vars

Reviewer checklist

  • Payroll tools require payroll.settings + payroll.employees or payroll.settings + payroll.timesheets — matches how you expect custom connections to be configured.
  • Acceptable that granular OAuth scope names (bearer-style) do not satisfy broad ToolScopes until we add an alias map (documented in README).
  • console.warn / optional console.error only to stderr (stdio MCP safe).

amanda-ducrou and others added 2 commits March 20, 2026 10:30
…registration logic

- Updated `.env.example` to include optional OAuth scopes and logging configurations.
- Refactored scope handling in `xero-client.ts` to utilize a new helper for scope validation.
- Introduced `scopes.ts` to manage default and valid scopes, improving clarity and maintainability.
- Modified tool creation functions to enforce required scopes, ensuring tools are registered based on configured permissions.
- Enhanced README with detailed instructions on scope usage and tool registration behavior.

This commit improves the flexibility and robustness of custom connections with the Xero API.
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