feat(blocks): introduce pluggable Block registry (no behavior change) #606
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Background / Problem
Ideal State:
register_block("my-kind")
lets you map the string"my-kind"
to a Python class that knows how to hold / validate / (de)serialize your custom data.{"kind": "my-kind", ...}
in JSON, it looks up the class in the registry instead of complaining“unknown kind”
.Goal
Add a tiny, stable API that lets external libraries register additional Block kinds at import-time, without touching MCP’s wire format or expanding the core code-base every time a new idea appears.
TLDR
Adds a lightweight Block registry so external packages can declare new kind strings without modifying the core SDK.
Key API:
from mcp.blocks.registry import register_block, get_block_class
@register_block("my-kind")
class MyBlock(Block): ...
No built-in Blocks exist today, so no other code files needed to be modified.
How Has This Been Tested?
Breaking Changes
Types of changes
Checklist
Additional context
· Scope
✔ Add src/mcp/blocks/registry.py
• register_block(kind) decorator
• get_block_class(kind) lookup
• list_block_kinds() / is_block_kind_registered() helpers
• UnknownBlockKindError for clearer exceptions
✔ Emit RuntimeWarning on duplicate registration (non-fatal, last one wins)
✔ Ship unit-tests (five cases)
✔ Add README snippet under “Custom blocks” showing basic usage
✘ No deserializer changes (none in repo yet)
✘ No spec or wire-format edits
· Design Notes