Skip to content

[McpBundle] Compiler pass for tools #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2025

Conversation

TomHart
Copy link

@TomHart TomHart commented Jul 19, 2025

Q A
Bug fix? no
New feature? yes
Docs? yes
Issues N/A
License MIT

Add a Compiler Pass to find tools and register them in the ToolChain

@TomHart TomHart mentioned this pull request Jul 19, 2025
@TomHart TomHart changed the title Compiler pass for tools [McpBundle] Compiler pass for tools Jul 19, 2025
@TomHart TomHart force-pushed the compiler_pass_for_tools branch from c61b564 to 58536bd Compare July 19, 2025 23:35
@TomHart TomHart force-pushed the compiler_pass_for_tools branch 2 times, most recently from da439c8 to b1c22fe Compare July 20, 2025 09:33
@chr-hertel chr-hertel added the MCP Bundle Issues & PRs about the MCP SDK integration bundle label Jul 20, 2025
Copy link
Contributor

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

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

Thanks @TomHart for working on this - this will def improve the usability with the bundle 👍
i left some comment and i think it would be great to rebase this on #165 - will merge that PR after some tests

@TomHart TomHart force-pushed the compiler_pass_for_tools branch 2 times, most recently from cd6c9f1 to 220575f Compare July 21, 2025 22:17
@TomHart
Copy link
Author

TomHart commented Jul 21, 2025

You're welcome @chr-hertel. I believe I've address everything you mentioned if you'd like to take another look whenever you have time.

@OskarStark
Copy link
Contributor

Could be a follow up PR, but I would like to have an attribute for this like in the agent

@TomHart TomHart force-pushed the compiler_pass_for_tools branch from 3b01c9b to 20ef42c Compare July 22, 2025 09:57
@TomHart
Copy link
Author

TomHart commented Jul 22, 2025

@chr-hertel my bad on missing the strict types, updated now and rebased into 1 commit

@OskarStark OskarStark requested a review from chr-hertel July 22, 2025 10:20
@@ -63,6 +63,11 @@ Configuration
sse:
url: 'http://localhost:8000/sse' # URL to SSE endpoint of MCP server

To add your tools to the MCP server, add the following tag::

#[AutoconfigureTag('mcp.tool')]
Copy link
Member

Choose a reason for hiding this comment

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

this is not the right recommendation IMO:

  • AutoconfigureTag (like all Autoconfigure* attributes) is about defining an autoconfiguration rule applying on all child types (its original intent is to be used on interfaces). Recommending to use it to apply a tag on a service directly is a bad idea, as it can have unintended side effects for non-final classes (as it will also impact autoconfigured services defined with child classes)
  • if the goal is to automatically tag autoconfigured services implementing ToolExecutorInterface with the mcp.tool to make it simpler for projects adding a custom tool, the solution is for the MCP bundle to register an autoconfiguration rule for ToolExecutorInterface, so that projects only need to implement the interface and be done with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking of using the attribute because it's currently hard to decide which interface is the right indicator for the tag here

@Nyholm, it would be the Symfony\AI\McpSdk\Capability\Tool\IdentifierInterface, right?

return;
}

$definition = new Definition(ToolChain::class);
Copy link
Member

Choose a reason for hiding this comment

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

you could always define a mcp.tool_chain service using a tagged iterator, and then defining a ToolExecutorInterface alias pointing at it (which projects can still override if they don't want to rely on the tool chain).
There is no need for this compiler pass IMO.

@TomHart
Copy link
Author

TomHart commented Jul 25, 2025

Sorry for the slow response, I've had tonsillitis so took some time to recover. So if I've understood correct (as some of these things are new to me), I'd create a definition of

    mcp.tool_chain:
        arguments:
            $executors: !tagged_iterator mcp.tool

    Symfony\AI\McpSdk\Capability\Tool\ToolExecutorInterface: mcp.tool_chain

And then apply the AutoconfigureTag attribute to the IdentifierInterface class, providing @Nyholm confirms that's the correct one to target.

is that correct @chr-hertel @stof?

@chr-hertel
Copy link
Contributor

@TomHart no worries at all, hope you're well again 🤞

You are correct here, two things are needed a) registering based on the IndentifierInterface and b) injecting the collection into the chain implementation

For a) we can't simply add the AutoconfigureTag attribute tho, since that class lives in a different lib than the bundle - the trick here could be, to use the registerForAutoconfiguration() method for than in McpBundle, see https://symfony.com/doc/current/service_container/tags.html#autoconfiguring-tags

For b) i think you could just move the service definition from the compiler pass into the bundle class as well and use tagged_iterator('mcp.tool') for injecting the tools

@TomHart
Copy link
Author

TomHart commented Jul 25, 2025

I've changed it around now. I couldn't get it working with the instanceof autoconfigure, it just never picked anything up for some reason. Could you take another look now and see what you think?

Not sure why PHPUnit is failing, could it be re-tried to just see if it's a blip?

Finally, had to change from array to iterable for tagged_iterator to work, if that's a problem to change I can see if there's any other solutions

@chr-hertel
Copy link
Contributor

Looks good to me now, can you please rebase - I just merged #165

Address comments

lint

Update src/mcp-bundle/CHANGELOG.md

Co-authored-by: Oskar Stark <[email protected]>

Update src/mcp-bundle/CHANGELOG.md

Co-authored-by: Oskar Stark <[email protected]>

Update src/mcp-bundle/doc/index.rst

Co-authored-by: Oskar Stark <[email protected]>

Update src/mcp-bundle/doc/index.rst

Co-authored-by: Oskar Stark <[email protected]>

Remove strict types

Change the approach used, removing the compiler pass

lint
@TomHart TomHart force-pushed the compiler_pass_for_tools branch from c408cc5 to 0a77af8 Compare July 25, 2025 15:09
@TomHart
Copy link
Author

TomHart commented Jul 25, 2025

Amazing! Done!

Copy link
Contributor

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

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

Looks good & works! :)

@chr-hertel
Copy link
Contributor

Thank you @TomHart.

@chr-hertel chr-hertel merged commit 66fff92 into symfony:main Jul 25, 2025
12 checks passed
@TomHart
Copy link
Author

TomHart commented Jul 25, 2025

@chr-hertel what's the best way to find the best priority issues to work on?

@chr-hertel
Copy link
Contributor

If you're up for something to just on, I'd always point to #16. I think Stores we're quite good progressed lately, but there are quite some Platforms that only are a draft, like OpenRouter or Replicate, but also some missing completely, like Deepseek or Perplexity.

One of my priority topics would be #167 - feel free to have a look at that PR and open PRs against that.

And other than that, the Store component has two extension points that could use some love, especially the Symfony\AI\Store\Document\LoaderInterface could use more implementations. Currently it's only a TextFileLoader, but could also be a PdfLoader, an RssLoader, an HtmlLoader, etc ...

Happy to guide you more if you tell me what's interesting to you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MCP Bundle Issues & PRs about the MCP SDK integration bundle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants