[Server] Fix: standardize error handling across handlers with MCP specificatio… (#124)
* fix: standardize error handling across handlers with MCP specification compliance * Update mcp-elements.md Co-authored-by: Christopher Hertel <mail@christopher-hertel.de> * docs: clarify error handling behavior for all element types * docs: remove unnecessary whitespace in mcp-elements.md * fix: simplify exception signatures to accept simple messages * refactor: use specific exceptions in examples for better error handling * feat: throw exceptions from reference provider instead of returning null --------- Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
This commit is contained in:
parent
8885d29a4e
commit
ca18caf29d
1 changed files with 278 additions and 185 deletions
|
|
@ -231,7 +231,7 @@ class GetPromptHandlerTest extends TestCase
|
|||
public function testHandlePromptNotFoundExceptionReturnsError(): void
|
||||
{
|
||||
$request = $this->createGetPromptRequest('nonexistent_prompt');
|
||||
$exception = new PromptNotFoundException($request);
|
||||
$exception = new PromptNotFoundException('nonexistent_prompt');
|
||||
|
||||
$this->referenceProvider
|
||||
->expects($this->once())
|
||||
|
|
@ -243,14 +243,14 @@ class GetPromptHandlerTest extends TestCase
|
|||
|
||||
$this->assertInstanceOf(Error::class, $response);
|
||||
$this->assertEquals($request->getId(), $response->id);
|
||||
$this->assertEquals(Error::METHOD_NOT_FOUND, $response->code);
|
||||
$this->assertEquals('Prompt not found for name: "nonexistent_prompt".', $response->message);
|
||||
$this->assertEquals(Error::RESOURCE_NOT_FOUND, $response->code);
|
||||
$this->assertEquals('Prompt not found: "nonexistent_prompt".', $response->message);
|
||||
}
|
||||
|
||||
public function testHandlePromptGetExceptionReturnsError(): void
|
||||
{
|
||||
$request = $this->createGetPromptRequest('failing_prompt');
|
||||
$exception = new PromptGetException($request, new \RuntimeException('Failed to get prompt'));
|
||||
$exception = new PromptGetException('Failed to get prompt');
|
||||
|
||||
$this->referenceProvider
|
||||
->expects($this->once())
|
||||
|
|
@ -263,7 +263,7 @@ class GetPromptHandlerTest extends TestCase
|
|||
$this->assertInstanceOf(Error::class, $response);
|
||||
$this->assertEquals($request->getId(), $response->id);
|
||||
$this->assertEquals(Error::INTERNAL_ERROR, $response->code);
|
||||
$this->assertEquals('Error while handling prompt: Handling prompt "failing_prompt" failed with error: "Failed to get prompt".', $response->message);
|
||||
$this->assertEquals('Failed to get prompt', $response->message);
|
||||
}
|
||||
|
||||
public function testHandlePromptGetWithComplexArguments(): void
|
||||
|
|
|
|||
Loading…
Reference in a new issue