feat: implement MCP server with tools, Post API tests, auth middleware
- Create TryPostServer MCP server with 17 tools:
Post (List, Get, Create, Delete), Hashtag (List, Create, Update, Delete),
Label (List, Create, Update, Delete), Workspace (Get),
ApiKey (List, Create, Delete)
- Create AuthenticateMcpToken middleware (logs in workspace owner)
- Register mcp.auth middleware alias in bootstrap/app.php
- Create routes/ai.php with mcp.trypost.test subdomain
- Add PostApiTest with 6 tests (list, show, create, delete, isolation)
- Fix PostApiTest assertions for pagination/resource wrapping
- 704 tests passing, frontend build passing
2026-03-29 23:30:36 +00:00
< ? php
declare ( strict_types = 1 );
namespace App\Mcp\Tools\ApiKey ;
2026-05-04 00:34:20 +00:00
use App\Http\Resources\Api\ApiKeyResource ;
2026-05-03 21:38:17 +00:00
use App\Models\AccessToken ;
feat: implement MCP server with tools, Post API tests, auth middleware
- Create TryPostServer MCP server with 17 tools:
Post (List, Get, Create, Delete), Hashtag (List, Create, Update, Delete),
Label (List, Create, Update, Delete), Workspace (Get),
ApiKey (List, Create, Delete)
- Create AuthenticateMcpToken middleware (logs in workspace owner)
- Register mcp.auth middleware alias in bootstrap/app.php
- Create routes/ai.php with mcp.trypost.test subdomain
- Add PostApiTest with 6 tests (list, show, create, delete, isolation)
- Fix PostApiTest assertions for pagination/resource wrapping
- 704 tests passing, frontend build passing
2026-03-29 23:30:36 +00:00
use Illuminate\Contracts\JsonSchema\JsonSchema ;
use Laravel\Mcp\Request ;
use Laravel\Mcp\Response ;
use Laravel\Mcp\ResponseFactory ;
use Laravel\Mcp\Server\Attributes\Description ;
use Laravel\Mcp\Server\Tool ;
2026-05-04 00:34:20 +00:00
#[Description('Create a new Personal Access Token (API key) for the current workspace. The plain token value is returned ONCE — store it immediately, it cannot be retrieved later.')]
feat: implement MCP server with tools, Post API tests, auth middleware
- Create TryPostServer MCP server with 17 tools:
Post (List, Get, Create, Delete), Hashtag (List, Create, Update, Delete),
Label (List, Create, Update, Delete), Workspace (Get),
ApiKey (List, Create, Delete)
- Create AuthenticateMcpToken middleware (logs in workspace owner)
- Register mcp.auth middleware alias in bootstrap/app.php
- Create routes/ai.php with mcp.trypost.test subdomain
- Add PostApiTest with 6 tests (list, show, create, delete, isolation)
- Fix PostApiTest assertions for pagination/resource wrapping
- 704 tests passing, frontend build passing
2026-03-29 23:30:36 +00:00
class CreateApiKeyTool extends Tool
{
public function handle ( Request $request ) : ResponseFactory
{
$validated = $request -> validate ([
'name' => [ 'required' , 'string' , 'max:255' ],
'expires_at' => [ 'nullable' , 'date' , 'after:now' ],
]);
2026-05-03 21:38:17 +00:00
$user = $request -> user ();
2026-05-04 00:34:20 +00:00
$result = $user -> createToken ( data_get ( $validated , 'name' ));
2026-05-03 21:38:17 +00:00
$token = AccessToken :: find ( $result -> token -> id );
$token -> forceFill ([
2026-05-04 00:34:20 +00:00
'workspace_id' => $user -> current_workspace_id ,
'expires_at' => data_get ( $validated , 'expires_at' ),
2026-05-03 21:38:17 +00:00
]) -> saveQuietly ();
feat: implement MCP server with tools, Post API tests, auth middleware
- Create TryPostServer MCP server with 17 tools:
Post (List, Get, Create, Delete), Hashtag (List, Create, Update, Delete),
Label (List, Create, Update, Delete), Workspace (Get),
ApiKey (List, Create, Delete)
- Create AuthenticateMcpToken middleware (logs in workspace owner)
- Register mcp.auth middleware alias in bootstrap/app.php
- Create routes/ai.php with mcp.trypost.test subdomain
- Add PostApiTest with 6 tests (list, show, create, delete, isolation)
- Fix PostApiTest assertions for pagination/resource wrapping
- 704 tests passing, frontend build passing
2026-03-29 23:30:36 +00:00
2026-05-04 00:34:20 +00:00
return Response :: structured ( array_merge (
( new ApiKeyResource ( $token )) -> resolve (),
[ 'token' => $result -> accessToken ],
));
feat: implement MCP server with tools, Post API tests, auth middleware
- Create TryPostServer MCP server with 17 tools:
Post (List, Get, Create, Delete), Hashtag (List, Create, Update, Delete),
Label (List, Create, Update, Delete), Workspace (Get),
ApiKey (List, Create, Delete)
- Create AuthenticateMcpToken middleware (logs in workspace owner)
- Register mcp.auth middleware alias in bootstrap/app.php
- Create routes/ai.php with mcp.trypost.test subdomain
- Add PostApiTest with 6 tests (list, show, create, delete, isolation)
- Fix PostApiTest assertions for pagination/resource wrapping
- 704 tests passing, frontend build passing
2026-03-29 23:30:36 +00:00
}
public function schema ( JsonSchema $schema ) : array
{
return [
2026-05-04 00:34:20 +00:00
'name' => $schema -> string () -> required () -> description ( 'A human-readable name to identify the key (e.g. "My integration").' ),
'expires_at' => $schema -> string () -> description ( 'Optional ISO 8601 expiration date (e.g. 2026-12-31). Must be in the future.' ),
feat: implement MCP server with tools, Post API tests, auth middleware
- Create TryPostServer MCP server with 17 tools:
Post (List, Get, Create, Delete), Hashtag (List, Create, Update, Delete),
Label (List, Create, Update, Delete), Workspace (Get),
ApiKey (List, Create, Delete)
- Create AuthenticateMcpToken middleware (logs in workspace owner)
- Register mcp.auth middleware alias in bootstrap/app.php
- Create routes/ai.php with mcp.trypost.test subdomain
- Add PostApiTest with 6 tests (list, show, create, delete, isolation)
- Fix PostApiTest assertions for pagination/resource wrapping
- 704 tests passing, frontend build passing
2026-03-29 23:30:36 +00:00
];
}
}