duck.contrib.mcp.testserver

MCP protocol feature test server.

This module provides a complete test MCP server implementation for validating Duck’s MCP support, including:

  • Tool registration and execution

  • Tool authorization using scopes

  • Server-to-client notifications

  • Progress notifications

  • Client sampling requests

  • Client root discovery

  • User elicitation requests

  • Resource listing and reading

  • Resource templates

  • Prompt generation

  • MCP session handling

  • SSE streaming transport

The server is intended for development and protocol verification only. It exposes /mcp as an MCP endpoint and can be connected to MCP clients such as MCP Inspector for testing supported features.

… rubric:: Example

Connect an MCP client to:

http://localhost:<port>/mcp

Authentication testing: Authorization: Bearer admin-token

The admin_test tool requires the admin scope.

Module Contents

Classes

TestMCPServer

MCP test server covering the main protocol features.

API

class duck.contrib.mcp.testserver.TestMCPServer(*args, **kwargs)[source]

Bases: duck.contrib.mcp.MCPView

MCP test server covering the main protocol features.

Initialization

Collect all @tool / @resource / @prompt decorated methods on this instance into lookup dicts.

async add(a: int, b: int) int[source]

Test addition tool.

async admin_test(message: str) dict[source]

Test scoped authorization.

Requires the client/user to have the admin scope.

async authenticate()[source]

Test authentication provider.

In a real server this would validate a token/session.

async hello_resource()[source]

Test resource.

name

‘duck-mcp-test-server’

sse

True

async test_elicitation()[source]

Test elicitation/create.

async test_notification(message: str) str[source]

Test sending custom notifications to the client.

This verifies that the active SSE stream receives server push messages.

async test_prompt(name: str)[source]

Test prompt generation.

async test_roots()[source]

Test roots/list.

async test_sampling(prompt: str)[source]

Test sampling/createMessage.

async user_profile(user_id: str)[source]
version

‘1.0.0’