Skip to content

Comments

chore(http): create constant for session id header#246

Open
EdouardCourty wants to merge 1 commit intomodelcontextprotocol:mainfrom
EdouardCourty:chore/create-constant-for-session-id-header
Open

chore(http): create constant for session id header#246
EdouardCourty wants to merge 1 commit intomodelcontextprotocol:mainfrom
EdouardCourty:chore/create-constant-for-session-id-header

Conversation

@EdouardCourty
Copy link

Motivation and Context

The Mcp-Session-Id value is re-written a few times in the codebase. It should be stored in a constant to avoid duplication.

How Has This Been Tested?

Tests are passing.

Breaking Changes

No behavioral or API change.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactor

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

*/
class StreamableHttpTransport extends BaseTransport
{
public const MCP_SESSION_ID_HEADER = 'Mcp-Session-Id';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not reuse the const in tests, and only go with private scope - maybe shorter as well?

Suggested change
public const MCP_SESSION_ID_HEADER = 'Mcp-Session-Id';
private const SESSION_HEADER = 'Mcp-Session-Id';

'Access-Control-Allow-Methods' => 'GET, POST, DELETE, OPTIONS',
'Access-Control-Allow-Headers' => 'Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID, Authorization, Accept',
'Access-Control-Expose-Headers' => 'Mcp-Session-Id',
'Access-Control-Allow-Headers' => 'Content-Type, '.self::MCP_SESSION_ID_HEADER.', Mcp-Protocol-Version, Last-Event-ID, Authorization, Accept',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about introducing a const here as well?

    private const ALLOWED_HEADER = [
        'Accept',
        'Authorization',
        'Content-Type',
        'Last-Event-ID',
        'Mcp-Protocol-Version',
        self::SESSION_HEADER,
    ];

in combination with:

Suggested change
'Access-Control-Allow-Headers' => 'Content-Type, '.self::MCP_SESSION_ID_HEADER.', Mcp-Protocol-Version, Last-Event-ID, Authorization, Accept',
'Access-Control-Allow-Headers' => implode(',', self::ALLOWED_HEADER),

Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @EdouardCourty - small adjustments. In general I'm not in favor of having too much coupling of code between tests and implementation - rather a nit pick, i know 👼

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.

2 participants