Skip to content

Commit a67161d

Browse files
mowens3claude
andcommitted
Add configurable key prefix for backward compatibility
Allow custom key prefix via constructor parameter. Defaults to 'mcp' but can be overridden (e.g., 'mcp_tools' for Drupal integration). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 60a1864 commit a67161d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ApiKey/ApiKeyManager.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
*/
1313
final class ApiKeyManager implements ApiKeyManagerInterface
1414
{
15-
private const KEY_PREFIX = 'mcp';
15+
private const DEFAULT_PREFIX = 'mcp';
1616

1717
public function __construct(
1818
private readonly StorageInterface $storage,
1919
private readonly ClockInterface $clock,
2020
private readonly string $pepper = '',
21+
private readonly string $keyPrefix = self::DEFAULT_PREFIX,
2122
) {}
2223

2324
public function createKey(string $label, array $scopes, ?int $ttlSeconds = null): array
@@ -49,7 +50,7 @@ public function createKey(string $label, array $scopes, ?int $ttlSeconds = null)
4950

5051
return [
5152
'key_id' => $keyId,
52-
'api_key' => self::KEY_PREFIX . '.' . $keyId . '.' . $secret,
53+
'api_key' => $this->keyPrefix . '.' . $keyId . '.' . $secret,
5354
];
5455
}
5556

@@ -96,7 +97,7 @@ public function validate(string $apiKey): ?ApiKey
9697
}
9798

9899
[$prefix, $keyId, $secret] = $parts;
99-
if ($prefix !== self::KEY_PREFIX || $keyId === '' || $secret === '') {
100+
if ($prefix !== $this->keyPrefix || $keyId === '' || $secret === '') {
100101
return null;
101102
}
102103

0 commit comments

Comments
 (0)