Skip to content

Add OAuth2 gateway to implement authorization for MCP#12

Merged
thekid merged 4 commits intomainfrom
feature/oauth-gateway
Jan 3, 2026
Merged

Add OAuth2 gateway to implement authorization for MCP#12
thekid merged 4 commits intomainfrom
feature/oauth-gateway

Conversation

@thekid
Copy link
Copy Markdown
Member

@thekid thekid commented Jan 1, 2026

This PR implements the server-side aspect of #11 based on prototype at https://gist.github.com/thekid/e6ca3935b82a5e79e3337b1f2c3a596d

Example

use io\modelcontextprotocol\McpServer;
use io\modelcontextprotocol\server\{ImplementationsIn, OAuth2Gateway, Clients, UseSession};
use web\Application;
use web\session\InFileSystem;

class Test extends Application {

  public function routes() {
    $clients= new class() extends Clients { /* TBI */ };

    $sessions= (new InFileSystem())->named('oauth');
    $gateway= new OAuth2Gateway('/oauth', $clients, new UseSession($sessions));

    $auth= /* Some class extending web.auth.Authentication */;

    $server= new McpServer(new ImplementationsIn('impl'));
    return [
      '/mcp'   => $gateway->authenticate($server),
      '/oauth' => $gateway->flow($auth, $sessions),
      '/.well-known/oauth-authorization-server' => $gateway->meta(),
    ];
  }
}

Note: The MCP inspector requires direct access to the OAuth metadata and flow even when its connection type is set the Proxy! See here for a CORS filter allowing this.

thekid added 2 commits January 2, 2026 10:03
Prevents BC/FC problems with xp-forge/web, see this comment:
#12 (comment)
@thekid thekid merged commit 786f952 into main Jan 3, 2026
14 checks passed
@thekid thekid deleted the feature/oauth-gateway branch January 3, 2026 09:40
@thekid
Copy link
Copy Markdown
Member Author

thekid commented Jan 3, 2026

Released in https://github.com/xp-forge/mcp/releases/tag/v0.8.0


⚠️ Please note meta() was renamed to metadata()! The example given in the README file reflects this: https://github.com/xp-forge/mcp?tab=readme-ov-file#authentication

@thekid thekid mentioned this pull request Jan 6, 2026
2 tasks
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