Skip to content

feat(mcp): per-repository ai-instructions endpoint#732

Merged
binaryk merged 3 commits into
10.xfrom
feat/repository-ai-instructions
Jun 3, 2026
Merged

feat(mcp): per-repository ai-instructions endpoint#732
binaryk merged 3 commits into
10.xfrom
feat/repository-ai-instructions

Conversation

@binaryk

@binaryk binaryk commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

What

Adds a built-in, auto-registered Restify endpoint:

GET /api/restify/{repository}/ai-instructions

It returns a client-agnostic markdown document describing every MCP-enabled tool of a repository — CRUD (index/show/store/update/delete as enabled) + actions + getters — each with its description and input parameters (required/optional/type). This is the "copy for AI" / "copy for LLM" source: paste it into any agent so it knows exactly which MCP tools the resource exposes and how to call them.

Why

Per review feedback on the growee side: the "copy for AI" helper belongs in Restify, at the repository level, not as per-action custom app code. It must rely fully on Restify's own schema generation so it can never drift from what the MCP server actually exposes.

How

  • New RepositoryAiInstructionsRenderer builds the markdown entirely from the existing MCP pipeline — McpTools::getRepositoryOperations() (enumerates all tools) + McpTools::getOperationDetails() (per-tool schema), wrapping each schema with JsonSchemaTypeFactory->object() exactly like WrapperToolHelpers::formatSchemaForDisplay(). No new schema/enumeration logic.
  • New RepositoryAiInstructionsController resolves + authorizes the repository via the normal RestifyRequest::repository() flow (allowRestify policy). Unknown / non-MCP repositories → 404; unauthorized tool access → 403.
  • Route registered in RoutesDefinition before the CRUD {repositoryId} route so ai-instructions is not captured as a resource id (same placement strategy as /actions and /getters).

Output shape

---
repository: leads
label: Leads Index
tools: 9
generated_by: laravel-restify
---

# leads — MCP tools

<repository description>

## leads-index-tool  ·  index
...
**Parameters**
- `page` — number, optional. ...

## leads-...-action-tool  ·  action
...

Tests

tests/MCP/RepositoryAiInstructionsTest.php:

  • authorized MCP repo → 200, markdown lists CRUD + action tools with required/optional params
  • repo without HasMcpTools → 404

Full tests/MCP suite green (53 tests). Pint clean.

🤖 Generated with Claude Code

binaryk and others added 2 commits June 3, 2026 12:28
Add GET /api/restify/{repository}/ai-instructions returning a
client-agnostic markdown document describing every MCP-enabled tool of a
repository (CRUD + actions + getters) with its description and input
parameters (required/optional/type).

Built entirely on the existing MCP pipeline (McpTools::getRepositoryOperations
+ getOperationDetails), so the output cannot drift from what the MCP server
actually exposes. Repository-level authorization is enforced via the normal
RestifyRequest::repository() resolution; per-tool visibility/permission
filtering is inherited from MCP discovery.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@what-the-diff

what-the-diff Bot commented Jun 3, 2026

Copy link
Copy Markdown

PR Summary

  • Cleanup of unused code sections: The team has removed some code that is no longer being used in src/Actions/Action.php. This should make the remaining code cleaner and easier to understand.
  • Refactoring architectural components: Certain methods originally focused on MCP invocation descriptor have been deleted, suggesting a modification in our system's core design. The removal of classes such as BuildMcpExamplePayloadAction and McpInvocationDescriptor further indicates this architectural shift.
  • Introduction of new AI instructions handling controller: A new RepositoryAiInstructionsController has been added, equipped to manage instructions from the AI. This includes the definition of a new route for such instructions.
  • Added a class for AI instructions rendering: The new RepositoryAiInstructionsRenderer class in src/MCP/AiInstructions/ enables system to convert AI instructions into visually comprehensible markdown format. This should enhance the clarity and utility of AI instructions.
  • Removal of redundant tests: To maintain focus on updated functionalities, previous tests associated with the now removed classes have been deleted.
  • Introduction of new test class: A new test class, RepositoryAiInstructionsTest, has been created to specifically test repositories that have AI instructions. This will ensure that our new feature works as expected.
  • Set-up and clean-up mechanisms for tests: Set up and teardown methods have been implemented in the testing suite that help manage cache and repository state post tests. This boosts the efficiency of our testing process.
  • Addition of specific tests: Specific tests have been designed to verify the functionality of the new feature. These include a test for validating appropriate responses for repositories with MCP tools, and another for dealing with potential errors that might occur when a repository lacks MCP tools.
  • Creation of a MCP-equipped repository for testing: A repository equipped with MCP tools has been defined for executing the new tests. New anonymous class that extends Repository serves the purpose. This ensures that our testing is robust and comprehensive.

The repository-level ai-instructions endpoint reuses the existing MCP
pipeline (McpTools::getRepositoryOperations + getOperationDetails), so the
per-action helper added earlier is no longer used by anything:

- remove Action::toMcpInvocationDescriptor() + buildRoute()
- delete McpInvocationDescriptor and BuildMcpExamplePayloadAction + tests

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@binaryk binaryk merged commit 364483b into 10.x Jun 3, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant