Skip to content

Add hc-run resource handler - #15

Draft
binrogithub wants to merge 1 commit into
masterfrom
codex/add-resource-handler-for-hc-run-uris
Draft

Add hc-run resource handler#15
binrogithub wants to merge 1 commit into
masterfrom
codex/add-resource-handler-for-hc-run-uris

Conversation

@binrogithub

Copy link
Copy Markdown
Owner

Motivation

  • Introduce a read-only resource handler to resolve hc-run://<run_id>/<artifact> URIs into artifact content for MCP integration.
  • Ensure artifact access is safe and deterministic by validating and normalizing artifact paths and preventing path traversal.
  • Provide sanitized outputs for markdown and JSON artifacts so downstream consumers receive predictable content_type and body values.

Description

  • Add new package scaffolding hc_agent with hc_agent/mcp/resources.py that implements HcRunResourceHandler, a minimal RunStore protocol, and handle_hc_run_resource convenience wrapper.
  • Implement parse_hc_run_uri to validate hc-run URIs, require a run id, forbid params/query/fragment, and block path traversal or unsafe characters.
  • Provide _build_response that returns text/markdown; charset=utf-8 for .md/.markdown and validates/parses JSON for .json, reserializing it with json.dumps(..., ensure_ascii=False, separators=(",",":")) to sanitize output.
  • Define explicit error types InvalidResourceUri, ResourceNotFound, and UnsupportedArtifactType and remove NULs from text and decode bytes with UTF-8 errors="replace" for robustness.

Testing

  • No automated tests were executed against the new handler as part of this change.
  • Files were created and committed (hc_agent/__init__.py, hc_agent/mcp/__init__.py, hc_agent/mcp/resources.py) and basic file presence was inspected successfully.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant