Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Capability/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
use Mcp\Event\ResourceTemplateListChangedEvent;
use Mcp\Event\ToolListChangedEvent;
use Mcp\Exception\InvalidCursorException;
use Mcp\Schema\Page;
use Mcp\Schema\Prompt;
use Mcp\Schema\Resource;
use Mcp\Schema\ResourceTemplate;
use Mcp\Schema\ServerCapabilities;
use Mcp\Schema\Tool;
use Mcp\Server\RequestHandler\Reference\Page;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
Expand Down
2 changes: 1 addition & 1 deletion src/Capability/Registry/ReferenceProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Mcp\Capability\Registry;

use Mcp\Server\RequestHandler\Reference\Page;
use Mcp\Schema\Page;

/**
* Interface for providing access to registered MCP elements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server\RequestHandler\Reference;
namespace Mcp\Schema;

/**
* @extends \ArrayObject<int|string, mixed>
* @phpstan-type PageItem Tool|Prompt|ResourceTemplate|Resource
*
* @extends \ArrayObject<int|string, PageItem>
*/
final class Page extends \ArrayObject
{
/**
* @param array<int|string, mixed> $references Items can be Tool, Prompt, ResourceTemplate, or Resource
* @param array<int|string, PageItem> $references Items can be Tool, Prompt, ResourceTemplate, or Resource
*/
public function __construct(
public readonly array $references,
Expand Down
6 changes: 3 additions & 3 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace Mcp;

use Mcp\JsonRpc\Handler;
use Mcp\Server\Builder;
use Mcp\Server\TransportInterface;
use Mcp\Server\Handler\JsonRpcHandler;
use Mcp\Server\Transport\TransportInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Uid\Uuid;
Expand All @@ -25,7 +25,7 @@
final class Server
{
public function __construct(
private readonly Handler $jsonRpcHandler,
private readonly JsonRpcHandler $jsonRpcHandler,
private readonly LoggerInterface $logger = new NullLogger(),
) {
}
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Mcp\Capability\Tool\ToolCaller;
use Mcp\Capability\Tool\ToolCallerInterface;
use Mcp\Exception\ConfigurationException;
use Mcp\JsonRpc\Handler;
use Mcp\Schema\Annotations;
use Mcp\Schema\Implementation;
use Mcp\Schema\Prompt;
Expand All @@ -39,6 +38,7 @@
use Mcp\Schema\Tool;
use Mcp\Schema\ToolAnnotations;
use Mcp\Server;
use Mcp\Server\Handler\JsonRpcHandler;
use Mcp\Server\Session\InMemorySessionStore;
use Mcp\Server\Session\SessionFactory;
use Mcp\Server\Session\SessionFactoryInterface;
Expand Down Expand Up @@ -334,7 +334,7 @@ public function build(): Server
$sessionStore = $this->sessionStore ?? new InMemorySessionStore($sessionTtl);

return new Server(
jsonRpcHandler: Handler::make(
jsonRpcHandler: JsonRpcHandler::make(
registry: $registry,
referenceProvider: $registry,
implementation: $this->serverInfo,
Expand Down
27 changes: 13 additions & 14 deletions src/JsonRpc/Handler.php → src/Server/Handler/JsonRpcHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Mcp\JsonRpc;
namespace Mcp\Server\Handler;

use Mcp\Capability\Prompt\PromptGetterInterface;
use Mcp\Capability\Registry\ReferenceProviderInterface;
Expand All @@ -20,15 +20,14 @@
use Mcp\Exception\HandlerNotFoundException;
use Mcp\Exception\InvalidInputMessageException;
use Mcp\Exception\NotFoundExceptionInterface;
use Mcp\JsonRpc\MessageFactory;
use Mcp\Schema\Implementation;
use Mcp\Schema\JsonRpc\Error;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Request;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\InitializeRequest;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\NotificationHandler;
use Mcp\Server\RequestHandler;
use Mcp\Server\Handler;
use Mcp\Server\Session\SessionFactoryInterface;
use Mcp\Server\Session\SessionInterface;
use Mcp\Server\Session\SessionStoreInterface;
Expand All @@ -41,7 +40,7 @@
*
* @author Christopher Hertel <[email protected]>
*/
class Handler
class JsonRpcHandler
{
/**
* @var array<int, MethodHandlerInterface>
Expand Down Expand Up @@ -80,15 +79,15 @@ public static function make(
sessionFactory: $sessionFactory,
sessionStore: $sessionStore,
methodHandlers: [
new NotificationHandler\InitializedHandler(),
new RequestHandler\InitializeHandler($registry->getCapabilities(), $implementation),
new RequestHandler\PingHandler(),
new RequestHandler\ListPromptsHandler($referenceProvider, $paginationLimit),
new RequestHandler\GetPromptHandler($promptGetter),
new RequestHandler\ListResourcesHandler($referenceProvider, $paginationLimit),
new RequestHandler\ReadResourceHandler($resourceReader),
new RequestHandler\CallToolHandler($toolCaller, $logger),
new RequestHandler\ListToolsHandler($referenceProvider, $paginationLimit),
new Notification\InitializedHandler(),
new Handler\Request\InitializeHandler($registry->getCapabilities(), $implementation),
new Handler\Request\PingHandler(),
new Handler\Request\ListPromptsHandler($referenceProvider, $paginationLimit),
new Handler\Request\GetPromptHandler($promptGetter),
new Handler\Request\ListResourcesHandler($referenceProvider, $paginationLimit),
new Handler\Request\ReadResourceHandler($resourceReader),
new Handler\Request\CallToolHandler($toolCaller, $logger),
new Handler\Request\ListToolsHandler($referenceProvider, $paginationLimit),
],
logger: $logger,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server;
namespace Mcp\Server\Handler;

use Mcp\Exception\ExceptionInterface;
use Mcp\Schema\JsonRpc\Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server\NotificationHandler;
namespace Mcp\Server\Handler\Notification;

use Mcp\Schema\JsonRpc\Error;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Notification\InitializedNotification;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server\RequestHandler;
namespace Mcp\Server\Handler\Request;

use Mcp\Capability\Tool\ToolCallerInterface;
use Mcp\Exception\ExceptionInterface;
use Mcp\Schema\JsonRpc\Error;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\CallToolRequest;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server\RequestHandler;
namespace Mcp\Server\Handler\Request;

use Mcp\Capability\Prompt\PromptGetterInterface;
use Mcp\Exception\ExceptionInterface;
use Mcp\Schema\JsonRpc\Error;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\GetPromptRequest;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server\RequestHandler;
namespace Mcp\Server\Handler\Request;

use Mcp\Schema\Implementation;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\InitializeRequest;
use Mcp\Schema\Result\InitializeResult;
use Mcp\Schema\ServerCapabilities;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server\RequestHandler;
namespace Mcp\Server\Handler\Request;

use Mcp\Capability\Registry\ReferenceProviderInterface;
use Mcp\Exception\InvalidCursorException;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\ListPromptsRequest;
use Mcp\Schema\Result\ListPromptsResult;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server\RequestHandler;
namespace Mcp\Server\Handler\Request;

use Mcp\Capability\Registry\ReferenceProviderInterface;
use Mcp\Exception\InvalidCursorException;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\ListResourcesRequest;
use Mcp\Schema\Result\ListResourcesResult;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server\RequestHandler;
namespace Mcp\Server\Handler\Request;

use Mcp\Capability\Registry\ReferenceProviderInterface;
use Mcp\Exception\InvalidCursorException;
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\ListToolsRequest;
use Mcp\Schema\Result\ListToolsResult;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server\RequestHandler;
namespace Mcp\Server\Handler\Request;

use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\PingRequest;
use Mcp\Schema\Result\EmptyResult;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server\RequestHandler;
namespace Mcp\Server\Handler\Request;

use Mcp\Capability\Resource\ResourceReaderInterface;
use Mcp\Exception\ExceptionInterface;
Expand All @@ -18,7 +18,7 @@
use Mcp\Schema\JsonRpc\HasMethodInterface;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\ReadResourceRequest;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionInterface;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Server/Transport/InMemoryTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Mcp\Server\Transport;

use Mcp\Server\TransportInterface;
use Symfony\Component\Uid\Uuid;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Server/Transport/StdioTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Mcp\Server\Transport;

use Mcp\Server\TransportInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Uid\Uuid;
Expand Down
1 change: 0 additions & 1 deletion src/Server/Transport/StreamableHttpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Mcp\Server\Transport;

use Mcp\Schema\JsonRpc\Error;
use Mcp\Server\TransportInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Mcp\Server;
namespace Mcp\Server\Transport;

use Symfony\Component\Uid\Uuid;

Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/JsonRpc/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Mcp\Tests\Unit\JsonRpc;

use Mcp\JsonRpc\Handler;
use Mcp\JsonRpc\MessageFactory;
use Mcp\Schema\JsonRpc\Response;
use Mcp\Server\MethodHandlerInterface;
use Mcp\Server\Handler\JsonRpcHandler;
use Mcp\Server\Handler\MethodHandlerInterface;
use Mcp\Server\Session\SessionFactoryInterface;
use Mcp\Server\Session\SessionInterface;
use Mcp\Server\Session\SessionStoreInterface;
Expand Down Expand Up @@ -56,7 +56,7 @@ public function testHandleMultipleNotifications()
$sessionFactory->method('createWithId')->willReturn($session);
$sessionStore->method('exists')->willReturn(true);

$jsonRpc = new Handler(
$jsonRpc = new JsonRpcHandler(
MessageFactory::make(),
$sessionFactory,
$sessionStore,
Expand Down Expand Up @@ -102,7 +102,7 @@ public function testHandleMultipleRequests()
$sessionFactory->method('createWithId')->willReturn($session);
$sessionStore->method('exists')->willReturn(true);

$jsonRpc = new Handler(
$jsonRpc = new JsonRpcHandler(
MessageFactory::make(),
$sessionFactory,
$sessionStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace Mcp\Tests\Unit\Server\RequestHandler;
namespace Mcp\Tests\Unit\Server\Handler\Request;

use Mcp\Capability\Tool\ToolCallerInterface;
use Mcp\Exception\ToolCallException;
Expand All @@ -19,7 +19,7 @@
use Mcp\Schema\JsonRpc\Response;
use Mcp\Schema\Request\CallToolRequest;
use Mcp\Schema\Result\CallToolResult;
use Mcp\Server\RequestHandler\CallToolHandler;
use Mcp\Server\Handler\Request\CallToolHandler;
use Mcp\Server\Session\SessionInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
Expand Down
Loading