Commit graph php-sdk/src/Server/Builder.php
Author SHA1 Message Date
Mateu Aguiló Bosch
fb2c8c2ee4
[Schema][Server] Add top-level title to Tool (#288)
* feat(schema): add top-level title to Tool

Mirror PR #278's Prompt change for Tool:

- Add optional ?string $title to Mcp\Schema\Tool between $name
  and $inputSchema. fromArray() now reads $data['title'];
  jsonSerialize() emits 'title' right after 'name'. The
  @phpstan-type ToolData gains title?: string.
- Add ?string $title to the #[McpTool] attribute between $name
  and $description.
- Note ToolAnnotations::$title as deprecated-for-display in
  favor of Tool::$title per MCP spec 2025-06-18 (PHPDoc only,
  field retained for BC).

Phase 1 of plan 01--tool-title-spec-compliance. Later phases
update Discoverer, Builder::addTool(), ArrayLoader, and the
conformance fixture to match the new signature.

* feat(server): thread title through discovery

- Discoverer::processMethod() now propagates McpTool::$title
  into every discovered Tool via named arguments.
- Builder::addTool() accepts ?string $title between $name and
  $description. [BC Break] positional callers passing the old
  $description as 3rd positional argument must switch to named
  arguments, matching the precedent set for addPrompt() in
  0.5.0.
- tests/Conformance/server.php migrated to named-argument form
  for every addTool() call.

Phase 2 of plan 01--tool-title-spec-compliance.

* feat(loader): forward title in ArrayLoader

ArrayLoader now reads 'title' from each tool config entry and
passes it into the Tool constructor, completing the wiring
from Builder::addTool() through array-driven registration.

The $tools @param array-shape typedef gains title: ?string
between name and description.

Phase 3 of plan 01--tool-title-spec-compliance.

* test(schema): cover Tool.title end-to-end

- New tests/Unit/Schema/ToolTest.php: constructor round-trip,
  jsonSerialize key-order when title set vs null, fromArray
  tolerance.
- New tests/Unit/Capability/Discovery/DiscovererToolTitleTest
  plus a TitleFixture class verifying McpTool(title: ...)
  propagates through discovery into the registered Tool.
- New tests/Unit/Capability/Registry/Loader/ArrayLoader...
  test verifying array-driven title propagation.
- Extend McpToolTest for title named-arg and default-null.
- Extend BuilderTest with addTool(title: 't') propagation.
- Update tests/Unit/.../RegistryTest, CallToolHandlerTest,
  ListToolsHandlerTest and examples/.../server.php
  new Tool(...) call sites to pass title (named args) so
  they match the new constructor signature.
- CHANGELOG 0.6.0 section: feature bullet + [BC Break]
  note for addTool() signature, mirroring 0.5.0 Prompt
  entries.
- docs/server-builder.md: addTool() row and prose now
  list title? between name and description.

Phase 4 of plan 01--tool-title-spec-compliance. All 730
phpunit tests pass; remaining phpstan warnings are
pre-existing and unrelated to Tool.title.

* refactor(schema): make Tool.title non-BC-breaking

Move `title` to the end of the Tool, Builder::addTool, and McpTool
attribute constructors with a default of null. This preserves
positional-argument compatibility and removes the need for
`title: null` boilerplate at call sites. JSON serialization order
(name, title, inputSchema, ...) is unchanged.

Also tighten the new tests: parameterize ToolTest with data
providers, fold the Discoverer title fixture into the existing
DiscoverableToolHandler, and drop the reflection-heavy Builder
test that overlapped with ArrayLoaderToolTitleTest.

* fix: move title after name

---------

Co-authored-by: DDEV User <nobody@example.com>
2026-04-26 15:37:40 +02:00
Christopher Hertel
7af5a345c1
Add title field to Prompt for MCP spec compliance (#278)
The MCP 2025-11-25 specification defines an optional `title` property on
Prompt for human-readable display in UI contexts, distinct from the
programmatic `name` identifier. This was missing from the SDK.

BC Break: Builder::addPrompt() signature changed — $title parameter added
between $name and $description. Callers using positional arguments for
$description must switch to named arguments.

Closes #276
2026-04-14 10:04:35 +02:00
Sule-Balogun Olanrewaju
ea38ef7b62
Fix to make Symfony Finder component optional (#267) 2026-04-11 17:19:47 +02:00
simon chrzanowski
faac4a525c
[Server] add a reference handler setter to server builder (#265)
* feat: add setReferenceHandler to Builder

Allow consumers to provide a custom ReferenceHandlerInterface
implementation (e.g. a security-aware decorator) instead of
always using the default ReferenceHandler.

* test: add BuilderTest for setReferenceHandler

- Fluent API returns builder instance
- build() succeeds with and without custom handler
- Integration test verifies custom handler intercepts tool calls

* style: fix codestyle in BuilderTest

* style: use imports instead of inline FQCNs in BuilderTest

* docs: add changelog entry for setReferenceHandler
2026-03-13 14:39:13 +01:00
Christopher Hertel
ae320646bf
Encapsulate session handling from protocol to new SessionManager (#247) 2026-03-10 18:09:15 +01:00
Edouard Courty
158e64627f
feat(server): add server lifecycle events (#175)
Signed-off-by: Edouard Courty <edouard.courty2@gmail.com>
2026-02-23 22:40:43 +01:00
Sule-Balogun Olanrewaju
2166b38d56
Add missing handler for resource subscribe and unsubscribe (#220) 2026-02-18 00:11:35 +01:00
Antoine Bluchet
7cb29125bd
Add interface abstractions for SchemaGenerator and Discoverer with DI improvements (#215)
* schema generator injection

* add interface for schema generator

* improve discoverer dependency

* remove some comments

* make some classes final

* simplify condition

* code review

* Extend changelog for covering interfaces

* Adopt SchemaGeneratorInterface after rebase and #153

---------

Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
2026-01-11 22:03:43 +01:00
Sule-Balogun Olanrewaju
c0938a19bd
feat: Add output schema support to MCP tools (#153) 2026-01-11 21:14:48 +01:00
Tobias Nyholm
69cd04f752
fix bug with Builder::addLoders() (#186) 2025-12-16 07:48:00 +01:00
Tobias Nyholm
a1e0f61b6b
Add RequestContext and logging (#176)
* Implemented MCP logging specification with auto-injection

* Add RequestContext

* fix tests and style

* Better deprecation

* fix: minor

* Remove ClientAwareInterface

* fix cs

* fix docs

---------

Co-authored-by: Adam Jamiu <jamiuadam120@gmail.com>
2025-12-16 00:12:02 +01:00
Antoine Bluchet
369932378f
align addLoaders with addRequestHandlers (#183) 2025-12-09 09:47:31 +01:00
Tobias Nyholm
b250f4ad1a
Allow users to not specify server info (#164)
* Allow users to not specify server info

* change to default name
2025-11-30 11:30:31 +01:00
Christopher Hertel
7cd281d0c7
Rework registry to combine provider and registry interface, move capabilities out and enable Registry injection in Builder (#150) 2025-11-20 19:36:57 +01:00
Bujar Begisholli - C24
7a58ab3f5a
Add meta to addPrompt and addResourceTemplate methods and null coalesce nullable properties (#149) 2025-11-14 17:11:38 +01:00
Christopher Hertel
056c7b6103
[Server] Add support for icons on explicit builder registration and attributes (#142)
* Add support for icons on explicit builder registration and attributes

* Update docs/server-builder.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-13 22:39:18 +01:00
Bujar Begisholli - C24
63ffeed0cc
[Server] Fix wrong parameter order when creating the tool from array (#147)
Previously, the meta parameter was incorrectly passed to the icons position
due to missing icons argument. Also adds icons support to Builder::addTool()
for consistency with the Tool schema.
2025-11-12 11:34:17 +01:00
Bujar Begisholli - C24
8daca8129e
[Server] Add meta parameter to addTool and addResource methods (#144) 2025-11-12 10:36:31 +01:00
Christopher Hertel
5804ba9773
Add support for icons and website url (#141) 2025-11-09 14:53:36 +01:00
Kaipi Yann
d3a07912b0
Roll out meta properties in attributes and more schema classes (#129) 2025-11-08 13:58:26 +01:00
ineersa
09596c0382
Ability to set custom protocol version (#117) 2025-11-08 00:37:01 +01:00
Antoine Bluchet
9be9e38815
ability to append loaders to server builder (#132) 2025-11-04 22:44:53 +01:00
Christopher Hertel
8885d29a4e
fix(server): add completion handler to builder (#126) 2025-10-30 11:49:13 +01:00
Kyrian Obikwelu
f1b471a219
[Server] Add Bidirectional Client Communication Support (#109)
* feat(server): add bidirectional client communication support

* fix(server): use correct session ID string conversion method

* fix: clean up docblocks for request handler methods in Builder

* fix: merge artifacts
2025-10-26 22:48:17 +01:00
Antoine Bluchet
e4a82f7474
refactor: registry loader (#111) 2025-10-24 21:43:16 +02:00
Kyrian Obikwelu
54a5d1495c
[Server] Refactor protocol pipeline to separate request and notification handling (#106) 2025-10-12 13:53:41 +01:00
Adebayo120
4486776e7d
[Server] Remove redundant Builder.setServerCapabilities method (#107) 2025-10-12 13:51:21 +01:00
ineersa
709a815cde
Add possibility to set custom ServerCapabilities. (#95) 2025-10-11 02:37:58 +02:00
Kyrian Obikwelu
fcf605d5d7
[Server] Simplify server extensibility with pluggable method handlers (#100)
* refactor: use a custom method handler registration system

* refactor: remove redundant Completer and CompleterInterface

* docs: update server-builder documentation to reflect custom method handler changes
2025-10-08 00:25:06 +02:00
Christopher Hertel
cbd1b298e9
Fix missing instructions from builder to handler (#90) 2025-10-07 23:32:51 +02:00
Christopher Hertel
d06b57d285
Address open PHPStan issues from baseline (#92) 2025-10-07 23:16:47 +02:00
Kyrian Obikwelu
4b91567dbd
feat: add completion/complete handler, centralize provider logic, and move completion capability (#97) 2025-10-07 10:34:50 +01:00
Kyrian Obikwelu
41486bfaa4
[Server] Reorganize server handlers and transport structure for better organization (#86)
* refactor: reorganize server handlers and transport structure

* feat: move the test files to corresponding directories

* fix: linter issues

* fix: correct PHPDoc formatting and streamline handler imports

* refactor: update import statement for ServerBuilder to Builder
2025-09-29 00:58:04 +02:00
Kyrian Obikwelu
3dcd2f717a
refactor: rename ServerBuilder to Builder (#85)
Remove redundant "Server" prefix since class is already in Server namespace.
2025-09-28 17:59:48 +01:00
Renamed from src/Server/ServerBuilder.php (Previous history)