elicitation.py
python
sha256:f99af7b1a7f36c4d537d1c630d4b71fc39222b1255f82e930929e2fc89015e11
fix: relax browse_repo perf budget to 500ms — 200ms was too…
Sonnet 4.6
99 days ago
| 1 | """Elicitation schemas for MCP 2025-11-25 form-mode elicitation. |
| 2 | |
| 3 | Defines the restricted JSON Schema objects (flat, primitive properties only) |
| 4 | used by MuseHub's elicitation-powered tools. Each schema conforms to the |
| 5 | subset allowed by the MCP spec: |
| 6 | - Object with primitive (string, number, boolean, enum) properties only. |
| 7 | - No nested objects or arrays of objects. |
| 8 | |
| 9 | Usage: |
| 10 | from musehub.mcp.elicitation import SCHEMAS, build_form_elicitation |
| 11 | |
| 12 | # In a tool executor: |
| 13 | elicitation_params = build_form_elicitation( |
| 14 | "release_metadata", |
| 15 | "Tell me about this release.", |
| 16 | request_id="elicit-1", |
| 17 | ) |
| 18 | """ |
| 19 | |
| 20 | import secrets |
| 21 | from typing import Final |
| 22 | |
| 23 | from musehub.types.json_types import JSONObject, JSONValue |
| 24 | |
| 25 | _REVIEW_DIMENSIONS: list[JSONValue] = [ |
| 26 | "all", "interface", "data", "logic", "tests", "infrastructure", |
| 27 | ] |
| 28 | |
| 29 | _REVIEW_DEPTHS: list[JSONValue] = ["quick", "standard", "thorough"] |
| 30 | |
| 31 | # ── Schema catalogue ────────────────────────────────────────────────────────── |
| 32 | |
| 33 | #: Ready-to-use JSON Schema objects for MuseHub elicitations. |
| 34 | SCHEMAS: Final[dict[str, JSONObject]] = { |
| 35 | # ── Proposal review focus ───────────────────────────────────────────────── |
| 36 | "proposal_review_focus": { |
| 37 | "type": "object", |
| 38 | "properties": { |
| 39 | "dimension_focus": { |
| 40 | "type": "string", |
| 41 | "title": "Dimension Focus", |
| 42 | "description": "Which area should the review concentrate on?", |
| 43 | "enum": _REVIEW_DIMENSIONS, |
| 44 | "default": "all", |
| 45 | }, |
| 46 | "review_depth": { |
| 47 | "type": "string", |
| 48 | "title": "Review Depth", |
| 49 | "description": "How thorough should the review be?", |
| 50 | "enum": _REVIEW_DEPTHS, |
| 51 | "default": "standard", |
| 52 | }, |
| 53 | "reviewer_note": { |
| 54 | "type": "string", |
| 55 | "title": "Reviewer Note", |
| 56 | "description": "Any specific concerns or guidance for the review (optional)", |
| 57 | "maxLength": 500, |
| 58 | }, |
| 59 | }, |
| 60 | "required": ["dimension_focus", "review_depth"], |
| 61 | }, |
| 62 | |
| 63 | # ── Release metadata ────────────────────────────────────────────────────── |
| 64 | "release_metadata": { |
| 65 | "type": "object", |
| 66 | "properties": { |
| 67 | "tag": { |
| 68 | "type": "string", |
| 69 | "title": "Release Tag", |
| 70 | "description": "Semantic version tag, e.g. v1.0.0", |
| 71 | "pattern": r"^v?\d+\.\d+(\.\d+)?(-[a-zA-Z0-9.]+)?$", |
| 72 | "minLength": 2, |
| 73 | "maxLength": 32, |
| 74 | }, |
| 75 | "title": { |
| 76 | "type": "string", |
| 77 | "title": "Release Title", |
| 78 | "description": "Short descriptive name for this release", |
| 79 | "minLength": 2, |
| 80 | "maxLength": 120, |
| 81 | }, |
| 82 | "release_notes": { |
| 83 | "type": "string", |
| 84 | "title": "Release Notes", |
| 85 | "description": "Changelog / what's new in this version", |
| 86 | "maxLength": 4000, |
| 87 | }, |
| 88 | "channel": { |
| 89 | "type": "string", |
| 90 | "title": "Distribution channel", |
| 91 | "description": "Channel for this release: stable | beta | alpha | nightly", |
| 92 | "default": "stable", |
| 93 | }, |
| 94 | "highlight": { |
| 95 | "type": "string", |
| 96 | "title": "Highlight (one sentence)", |
| 97 | "description": "Single sentence describing the most exciting change", |
| 98 | "maxLength": 280, |
| 99 | }, |
| 100 | }, |
| 101 | "required": ["tag", "title"], |
| 102 | }, |
| 103 | } |
| 104 | |
| 105 | AVAILABLE_REVIEW_DIMS: list[JSONValue] = _REVIEW_DIMENSIONS |
| 106 | |
| 107 | |
| 108 | # ── Builder helpers ─────────────────────────────────────────────────────────── |
| 109 | |
| 110 | def build_form_elicitation( |
| 111 | schema_key: str, |
| 112 | message: str, |
| 113 | *, |
| 114 | request_id: str | None = None, |
| 115 | ) -> JSONObject: |
| 116 | """Return an MCP elicitation request dict for ``schema_key``. |
| 117 | |
| 118 | Args: |
| 119 | schema_key: Key into :data:`SCHEMAS`. |
| 120 | message: Human-readable prompt shown to the user. |
| 121 | request_id: Unique elicitation ID; auto-generated if omitted. |
| 122 | |
| 123 | Returns: |
| 124 | A dict suitable for returning from an MCP tool as an elicitation request. |
| 125 | |
| 126 | Raises: |
| 127 | KeyError: If ``schema_key`` is not in :data:`SCHEMAS`. |
| 128 | """ |
| 129 | schema = SCHEMAS[schema_key] |
| 130 | return { |
| 131 | "type": "elicitation", |
| 132 | "id": request_id or secrets.token_hex(8), |
| 133 | "message": message, |
| 134 | "schema": schema, |
| 135 | } |
File History
2 commits
sha256:f99af7b1a7f36c4d537d1c630d4b71fc39222b1255f82e930929e2fc89015e11
fix: relax browse_repo perf budget to 500ms — 200ms was too…
Sonnet 4.6
99 days ago
sha256:763eb2cb8675073b84c19345b27586d2ed939a9aee97c5479b69f502f1a70eff
fix(tests): update test suite to match current implementation
Sonnet 4.6
patch
120 days ago