php-sdk/examples/server/oauth-keycloak/docker-compose.yml
Volodymyr Panivko e3f4b88768
[Server] Oauth2 based on middleware (#221)
* Add Middleware handlers to StreamableHttpTransport

* OAuth Implementation based on middleware

* OAuth Implementation based on middleware

* Add Middleware handlers to StreamableHttpTransport

* OAuth Implementation based on middleware

* OAuth Implementation based on middleware

Signed-off-by: Volodymyr Panivko <sveneld300@gmail.com>

* Address PR review feedback for OAuth middleware

* Apply php-cs-fixer to satisfy QA

* Use Mcp exception classes in OAuth middleware

* Refactor OAuth HTTP stack and add Microsoft example policies

* Fix QA PHPStan findings in OAuth examples and auth middleware

* Require OIDC discovery in JWKS provider and refine OAuth proxy behavior

* Remove local development docker artifacts from VCS

* Revert .gitignore changes for local docker files

* Fix body retrieval in OAuthRequestMetaMiddleware for proper string conversion

Signed-off-by: Volodymyr Panivko <sveneld300@gmail.com>

* Address OAuth PR review feedback and align example configs

* Fix QA style issues and add authorization docs

* Fix PHPStan typing issues in OAuth middleware

* Remove duplicate Middleware namespace, consolidate under Http\Middleware

Remove old Mcp\Server\Transport\Middleware\ classes that were duplicated
in Mcp\Server\Transport\Http\Middleware\ and Http\OAuth\. Update docs
to reference the correct namespaces.

* Address PR review: replace Throwable catch with specific exceptions, add JSON_THROW_ON_ERROR

- JwtTokenValidator: replace catch(\Throwable) with explicit
  \InvalidArgumentException|\UnexpectedValueException|\DomainException,
  letting RuntimeException from JwksProvider propagate as infrastructure errors
- OAuthProxyMiddleware: add \JSON_THROW_ON_ERROR to json_encode for metadata response
- Update tests to expect RuntimeException for JWKS infrastructure failures

---------

Signed-off-by: Volodymyr Panivko <sveneld300@gmail.com>
Co-authored-by: Volodymyr Panivko <volodymyr.panivko@togethernetworks.com>
2026-03-10 17:10:07 +01:00

69 lines
1.9 KiB
YAML

services:
keycloak:
image: quay.io/keycloak/keycloak:24.0
container_name: mcp-keycloak
environment:
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
KC_HEALTH_ENABLED: "true"
volumes:
- ./keycloak/mcp-realm.json:/opt/keycloak/data/import/mcp-realm.json:ro
command:
- start-dev
- --import-realm
- --http-port=8180
ports:
- "8180:8180"
healthcheck:
test: ["CMD-SHELL", "exec 3<>/dev/tcp/127.0.0.1/8180;echo -e 'GET /health/ready HTTP/1.1\r\nhost: localhost\r\nConnection: close\r\n\r\n' >&3;if [ $? -eq 0 ]; then echo 'Healthcheck Successful';exit 0;else echo 'Healthcheck Failed';exit 1;fi;"]
interval: 10s
timeout: 5s
retries: 15
start_period: 30s
networks:
- mcp-network
php:
build:
context: .
dockerfile: Dockerfile
container_name: mcp-php
volumes:
- ../../../:/app
working_dir: /app
environment:
KEYCLOAK_EXTERNAL_URL: http://localhost:8180
KEYCLOAK_INTERNAL_URL: http://keycloak:8180
KEYCLOAK_REALM: mcp
MCP_AUDIENCE: mcp-server
depends_on:
keycloak:
condition: service_healthy
command: >
sh -c "mkdir -p /app/examples/server/oauth-keycloak/sessions;
chmod -R 0777 /app/examples/server/oauth-keycloak/sessions;
touch /app/examples/server/oauth-keycloak/dev.log;
chmod 0666 /app/examples/server/oauth-keycloak/dev.log;
touch /app/examples/server/dev.log;
chmod 0666 /app/examples/server/dev.log;
composer install --no-interaction --quiet 2>/dev/null || true;
php-fpm"
networks:
- mcp-network
nginx:
image: nginx:alpine
container_name: mcp-nginx
ports:
- "8000:80"
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
- ../../../:/app:ro
depends_on:
- php
networks:
- mcp-network
networks:
mcp-network:
driver: bridge