Skip to content

feat: improve error handling for empty or malformed tool files - #528

Merged
valebearzotti merged 3 commits into
basementstudio:canaryfrom
FiammaMuscari:feat/tool-loader-error-handling
Mar 27, 2026
Merged

feat: improve error handling for empty or malformed tool files#528
valebearzotti merged 3 commits into
basementstudio:canaryfrom
FiammaMuscari:feat/tool-loader-error-handling

Conversation

@FiammaMuscari

Copy link
Copy Markdown
Contributor

Closes #464

This PR improves error handling when loading tool files.

  • Skips empty files and missing default exports with clear, friendly warnings
  • Includes the file path in error messages for invalid tool implementations
  • Preserves full stack traces for real syntax/import errors
  • Adds a startup summary for skipped tools
  • Avoids repeated warning spam

Tests:

  • added regression tests for skipped tool files
  • ensured file path is included in failure cases
  • verified real errors still surface correctly

@greptile-apps

greptile-apps Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@vercel

vercel Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

@FiammaMuscari is attempting to deploy a commit to the xmcp Team on Vercel.

A member of the Team first needs to authorize it.

@0xKoller 0xKoller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR @FiammaMuscari!

Looks promising overall. Before a thorough review, could you please add:

  • A concrete usage example
  • Screenshots
  • Documentation updates

Also it seems that some code has been dragged from the #527 , please remove.

@FiammaMuscari
FiammaMuscari force-pushed the feat/tool-loader-error-handling branch from bac36ca to 717c6ef Compare March 20, 2026 15:28
@FiammaMuscari

Copy link
Copy Markdown
Contributor Author

Updated the PR to remove the unrelated code that had been dragged from #527.

Also added:

  • a concrete usage example
  • a documentation update in the Tools docs
  • a terminal screenshot showing the new startup warning for an empty tool file

Example output:
[xmcp] Failed to load tool file: src/tools/draft.ts
-> File is empty.
[xmcp] 1 tool skipped due to empty files or missing default exports

Real syntax/import errors are still preserved and surface with full stack traces; only empty files and missing default exports are handled gracefully.

image (6)

@0xKoller 0xKoller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good path! There are some changes that need to be done but besides that everything seems good.

Comment thread apps/website/content/docs/core-concepts/tools.mdx Outdated
Comment thread packages/xmcp/src/runtime/utils/__tests__/tool-loader.test.ts Outdated
@FiammaMuscari

Copy link
Copy Markdown
Contributor Author

Moved this to a Troubleshooting section in the Tools docs in eb3d9cc.

@valebearzotti

Copy link
Copy Markdown
Collaborator

Hey @FiammaMuscari !

I personally really like this implementation and it'd be great to see the same for resources & prompts. Can we do the same for the other components? And maybe put all loaders (tool-loader, resource-, prompt-) in the same folder?

I'm gonna approve this PR, please continue with the remaining changes in a separate one. Thanks!

@FiammaMuscari

Copy link
Copy Markdown
Contributor Author

Great, I’ll address this in a follow-up PR

@valebearzotti
valebearzotti merged commit 8fcf289 into basementstudio:canary Mar 27, 2026
1 of 2 checks passed
@FiammaMuscari

Copy link
Copy Markdown
Contributor Author

Follow-up PR: #538

This continues the review feedback from #528 by extending the same graceful startup handling to prompts and resources in a separate, minimal PR.

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.

[Feature]: Improve error handling for empty or malformed tool files

3 participants