Skip to content

Conversation

@AleksandrParamonoff
Copy link
Contributor

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the required flag from the project name parameter in the MCP Server Tools, allowing the project parameter to be optional with a default value instead of mandatory.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@AleksandrParamonoff AleksandrParamonoff force-pushed the fix-required-flag-for-the-project-parameter branch from 7587173 to 33c2228 Compare October 24, 2025 10:33
@coderabbitai
Copy link

coderabbitai bot commented Oct 24, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Summary by CodeRabbit

  • New Features

    • Improved project parameter handling with clearer precedence rules—request parameters take priority over HTTP headers and environment variables.
  • Bug Fixes

    • Enhanced error messaging when a project parameter is not found from any source.
    • Whitespace trimming applied to project values for consistency.
  • Tests

    • Expanded test coverage for project parameter precedence and edge cases.

Walkthrough

Request-provided "project" parameters now take precedence (trimmed) over context sources; when absent, extraction falls back to HTTP header (HTTP mode) or environment/context (stdio mode). Removed DefaultProject propagation; tests and mocks updated to reflect new precedence and whitespace behavior.

Changes

Cohort / File(s) Summary
Project extraction & utilities
internal/reportportal/utils.go
extractProject now prefers the trimmed request parameter "project"; if empty, falls back to context-derived project; returns descriptive error when neither source supplies a project. Removed newProjectParameter.
Resource constructors / server wiring
internal/reportportal/launches.go, internal/reportportal/items.go, internal/reportportal/http_server.go, internal/reportportal/server.go, cmd/reportportal-mcp-server/main.go
Removed propagation of a DefaultProject argument across server and resource constructors. NewLaunchResources and NewTestItemResources signatures now drop the defaultProject parameter and create a generic project MCP parameter via mcp.WithString(...). HTTPServerConfig no longer carries DefaultProject; stdio startup may inject project into context when --project is set.
Tests & mocks
internal/reportportal/utils_project_test.go, internal/reportportal/integration_project_test.go, internal/reportportal/mock_test.go, internal/reportportal/launches_test.go
Tests refactored to mode-based scenarios (HTTP vs stdio), added cases for whitespace trimming, empty values, and precedence where request parameter overrides header; mock helper extractProjectWithMock now prefers mock request project then falls back to context, returning explicit error when absent.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client (MCP request)
    participant HTTP as HTTP Handler
    participant Utils as extractProject
    participant Context as Request Context / Env

    Note over Client,HTTP: Incoming request with optional sources\n(request param, X-Project header)
    Client->>HTTP: POST /tool-call (with request.project?, X-Project?)
    HTTP->>Utils: extractProject(rq, ctx)
    Utils->>Utils: trim(request.project)
    alt request.project non-empty
        Utils-->>HTTP: return request.project
    else request.project empty
        alt X-Project header present (HTTP mode)
            Utils-->>HTTP: return header value
        else context/env provides project
            Utils-->>HTTP: return context project
        else
            Utils-->>HTTP: return error ("no project parameter found...")
        end
    end
    HTTP-->>Client: proceed or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • AmsterGet
  • avarabyeu

Poem

Project in request, trimmed and bright,
Headers stand by in the dimmer light,
Context waits patient if both take flight,
Tests sing the order, neat and tight,
Small change, clear path — code sleeps well tonight.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request has no description provided by the author. An absent description does not describe any part of the changeset, which fails to meet the lenient criterion that the description should be related in some way to the modifications. While the title and file changes provide some context, a description would help reviewers understand the motivation, rationale, and impact of removing the defaultProject parameter and restructuring the project extraction logic across multiple components. The author should add a description explaining the key changes and their rationale. For example, they could describe why the project parameter handling is being refactored from configuration-time defaults to request-time extraction, how the new precedence (request parameter > HTTP header > environment/context) improves the behavior, and any potential implications for users or downstream code that previously relied on the defaultProject parameter.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "EPMRPP-108935 || MCP Server. Tools. Fix rp project parameter configuration" is descriptive and directly related to the main changeset. It clearly indicates that this PR fixes the project parameter configuration for MCP Server tools, which aligns with the core changes: removing the defaultProject parameter from resource constructors and refactoring project extraction logic to prioritize request parameters over other sources. The title includes the JIRA key for traceability and uses a clear "Fix" indicator. While it doesn't strictly follow the conventional commit format (e.g., fix(scope): description), it does include all relevant information and appears to follow the project's conventions.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-required-flag-for-the-project-parameter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@AleksandrParamonoff AleksandrParamonoff changed the title EPMRPP-108935 || MCP Server. Tools. Remove required flag for the project name parameter EPMRPP-108935 || MCP Server. Tools. Fix rp project parameter configuration Oct 24, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f46779 and 33c2228.

📒 Files selected for processing (4)
  • internal/reportportal/integration_project_test.go (4 hunks)
  • internal/reportportal/mock_test.go (1 hunks)
  • internal/reportportal/utils.go (1 hunks)
  • internal/reportportal/utils_project_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.go

📄 CodeRabbit inference engine (README.md)

**/*.go: Go code must be formatted consistently; run the formatter (task fmt) on all Go source files
Go code should pass lint checks (task lint) before submission
When adding a new MCP tool, implement it as a method in the appropriate resource Go file returning (mcp.Tool, server.ToolHandlerFunc) and register it in NewServer via s.AddTool(...)

Files:

  • internal/reportportal/utils_project_test.go
  • internal/reportportal/integration_project_test.go
  • internal/reportportal/utils.go
  • internal/reportportal/mock_test.go

⚙️ CodeRabbit configuration file

Focus on Go best practices, error handling, concurrency safety, performance, and security. Check for proper resource cleanup and context handling.

Files:

  • internal/reportportal/utils_project_test.go
  • internal/reportportal/integration_project_test.go
  • internal/reportportal/utils.go
  • internal/reportportal/mock_test.go
**/*_test.go

⚙️ CodeRabbit configuration file

Ensure comprehensive test coverage, proper test isolation, meaningful assertions, and good test naming conventions.

Files:

  • internal/reportportal/utils_project_test.go
  • internal/reportportal/integration_project_test.go
  • internal/reportportal/mock_test.go
internal/reportportal/**

⚙️ CodeRabbit configuration file

Pay special attention to API integration patterns, error handling, data validation, and MCP protocol compliance.

Files:

  • internal/reportportal/utils_project_test.go
  • internal/reportportal/integration_project_test.go
  • internal/reportportal/utils.go
  • internal/reportportal/mock_test.go
🧬 Code graph analysis (4)
internal/reportportal/utils_project_test.go (2)
internal/reportportal/http_token_middleware.go (1)
  • WithProjectInContext (113-117)
internal/reportportal/mock_test.go (1)
  • MockCallToolRequest (11-13)
internal/reportportal/integration_project_test.go (1)
internal/reportportal/mock_test.go (1)
  • MockCallToolRequest (11-13)
internal/reportportal/utils.go (1)
internal/reportportal/http_token_middleware.go (1)
  • GetProjectFromContext (120-124)
internal/reportportal/mock_test.go (1)
internal/reportportal/http_token_middleware.go (1)
  • GetProjectFromContext (120-124)
🔇 Additional comments (4)
internal/reportportal/integration_project_test.go (2)

12-76: Excellent test coverage for the new precedence logic.

The test cases comprehensively validate:

  • Request parameter precedence over HTTP header
  • Fallback behavior when request parameter is missing
  • Whitespace trimming for both sources
  • Error handling when no project is available
  • Empty vs. whitespace value handling

The test names are clear and self-documenting.


116-156: Test correctly validates request parameter precedence in complete HTTP flow.

The integration test properly verifies that the request parameter takes precedence over the HTTP header in a realistic scenario. The test setup and assertions align with the updated precedence logic.

internal/reportportal/utils_project_test.go (2)

10-146: Comprehensive mode-based test coverage with excellent precedence validation.

The restructured tests effectively validate:

  • Mode-based project source selection (stdio vs HTTP)
  • Proper precedence: request → header/env → error
  • Whitespace trimming across all sources
  • Mode isolation (header ignored in stdio, env ignored in HTTP)
  • Edge cases (empty, whitespace-only values)

The descriptive test names make the expected behavior clear. This is thorough test design.


148-179: Test implementation correctly validates mode-based project extraction.

The test execution properly:

  • Switches context source based on mode (HTTP header vs environment variable)
  • Uses the appropriate context helper (WithProjectInContext)
  • Validates both success and error scenarios
  • Asserts the correct project value is extracted

The implementation aligns well with the updated production logic.

@AleksandrParamonoff AleksandrParamonoff force-pushed the fix-required-flag-for-the-project-parameter branch from 33c2228 to da56589 Compare October 24, 2025 10:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

func runStdioServer(ctx context.Context, cmd *cli.Command) error {
rpProject := cmd.String("project")
if rpProject != "" {
// Add project to request context default project name from Environment variable
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

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

Corrected grammar: 'Add project to request context as default project name from environment variable'.

Suggested change
// Add project to request context default project name from Environment variable
// Add project to request context if project name is provided

Copilot uses AI. Check for mistakes.
analytics: analytics,
client: client,
projectParameter: mcp.WithString("project", // Parameter for specifying the project name)
mcp.Description("Project name"),
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

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

The project parameter is no longer marked as required and has no default value. This could lead to runtime errors if callers don't provide the project through any of the three sources (request, HTTP header, or environment variable). Consider documenting the fallback behavior in the parameter description.

Suggested change
mcp.Description("Project name"),
mcp.Description("Project name. If not provided, the value will be determined from the request, HTTP header, or environment variable."),

Copilot uses AI. Check for mistakes.
analytics: analytics,
client: client,
projectParameter: mcp.WithString("project", // Parameter for specifying the project name)
mcp.Description("Project name"),
Copy link

Copilot AI Oct 24, 2025

Choose a reason for hiding this comment

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

The project parameter is no longer marked as required and has no default value. This could lead to runtime errors if callers don't provide the project through any of the three sources (request, HTTP header, or environment variable). Consider documenting the fallback behavior in the parameter description.

Suggested change
mcp.Description("Project name"),
mcp.Description("Project name"),
mcp.Required(),

Copilot uses AI. Check for mistakes.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33c2228 and da56589.

📒 Files selected for processing (10)
  • cmd/reportportal-mcp-server/main.go (1 hunks)
  • internal/reportportal/http_server.go (2 hunks)
  • internal/reportportal/integration_project_test.go (4 hunks)
  • internal/reportportal/items.go (1 hunks)
  • internal/reportportal/launches.go (1 hunks)
  • internal/reportportal/launches_test.go (1 hunks)
  • internal/reportportal/mock_test.go (1 hunks)
  • internal/reportportal/server.go (3 hunks)
  • internal/reportportal/utils.go (1 hunks)
  • internal/reportportal/utils_project_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.go

📄 CodeRabbit inference engine (README.md)

**/*.go: Go code must be formatted consistently; run the formatter (task fmt) on all Go source files
Go code should pass lint checks (task lint) before submission
When adding a new MCP tool, implement it as a method in the appropriate resource Go file returning (mcp.Tool, server.ToolHandlerFunc) and register it in NewServer via s.AddTool(...)

Files:

  • internal/reportportal/mock_test.go
  • cmd/reportportal-mcp-server/main.go
  • internal/reportportal/server.go
  • internal/reportportal/items.go
  • internal/reportportal/http_server.go
  • internal/reportportal/launches_test.go
  • internal/reportportal/utils_project_test.go
  • internal/reportportal/launches.go
  • internal/reportportal/integration_project_test.go
  • internal/reportportal/utils.go

⚙️ CodeRabbit configuration file

Focus on Go best practices, error handling, concurrency safety, performance, and security. Check for proper resource cleanup and context handling.

Files:

  • internal/reportportal/mock_test.go
  • cmd/reportportal-mcp-server/main.go
  • internal/reportportal/server.go
  • internal/reportportal/items.go
  • internal/reportportal/http_server.go
  • internal/reportportal/launches_test.go
  • internal/reportportal/utils_project_test.go
  • internal/reportportal/launches.go
  • internal/reportportal/integration_project_test.go
  • internal/reportportal/utils.go
**/*_test.go

⚙️ CodeRabbit configuration file

Ensure comprehensive test coverage, proper test isolation, meaningful assertions, and good test naming conventions.

Files:

  • internal/reportportal/mock_test.go
  • internal/reportportal/launches_test.go
  • internal/reportportal/utils_project_test.go
  • internal/reportportal/integration_project_test.go
internal/reportportal/**

⚙️ CodeRabbit configuration file

Pay special attention to API integration patterns, error handling, data validation, and MCP protocol compliance.

Files:

  • internal/reportportal/mock_test.go
  • internal/reportportal/server.go
  • internal/reportportal/items.go
  • internal/reportportal/http_server.go
  • internal/reportportal/launches_test.go
  • internal/reportportal/utils_project_test.go
  • internal/reportportal/launches.go
  • internal/reportportal/integration_project_test.go
  • internal/reportportal/utils.go
cmd/**

⚙️ CodeRabbit configuration file

Review CLI interface design, configuration handling, and application startup logic for robustness and usability.

Files:

  • cmd/reportportal-mcp-server/main.go
🧬 Code graph analysis (8)
internal/reportportal/mock_test.go (1)
internal/reportportal/http_token_middleware.go (1)
  • GetProjectFromContext (120-124)
cmd/reportportal-mcp-server/main.go (1)
internal/reportportal/http_token_middleware.go (1)
  • WithProjectInContext (113-117)
internal/reportportal/server.go (2)
internal/reportportal/launches.go (1)
  • NewLaunchResources (25-36)
internal/reportportal/items.go (1)
  • NewTestItemResources (25-36)
internal/reportportal/http_server.go (2)
internal/reportportal/launches.go (1)
  • NewLaunchResources (25-36)
internal/reportportal/items.go (1)
  • NewTestItemResources (25-36)
internal/reportportal/launches_test.go (1)
internal/reportportal/launches.go (1)
  • NewLaunchResources (25-36)
internal/reportportal/utils_project_test.go (2)
internal/reportportal/http_token_middleware.go (1)
  • WithProjectInContext (113-117)
internal/reportportal/mock_test.go (1)
  • MockCallToolRequest (11-13)
internal/reportportal/integration_project_test.go (1)
internal/reportportal/mock_test.go (1)
  • MockCallToolRequest (11-13)
internal/reportportal/utils.go (1)
internal/reportportal/http_token_middleware.go (1)
  • GetProjectFromContext (120-124)
🔇 Additional comments (11)
internal/reportportal/utils_project_test.go (1)

10-179: Excellent comprehensive test coverage for project extraction logic!

The test cases thoroughly cover:

  • Precedence rules across modes (request > header/env)
  • Whitespace trimming for all sources
  • Empty value fallback behavior
  • Error cases when no project is available
  • Mode-specific behavior (HTTP vs stdio)

The test structure is clear, well-organized, and validates all critical paths in the new project extraction logic.

internal/reportportal/mock_test.go (1)

61-73: LGTM! Comment accurately reflects fallback precedence.

The function correctly implements the new project extraction logic:

  1. Request parameter has highest priority (with trimming)
  2. Context-based project as fallback
  3. Clear error when neither source provides a project

The comment on line 68 has been updated per previous review feedback and now accurately describes this as a fallback rather than the first attempt.

internal/reportportal/launches_test.go (1)

46-46: Constructor call correctly updated to match new API.

The call to NewLaunchResources now properly uses the simplified signature (client, analytics) without the defaultProject parameter. The test correctly provides the project value via request arguments (line 58), aligning with the new parameter-based approach.

internal/reportportal/server.go (2)

19-25: Public API signature updated to remove defaultProject parameter.

The function signature change removes the defaultProject parameter, which aligns with the PR's objective to eliminate DefaultProject propagation. This is a breaking change but is intentional and well-coordinated with updates to resource constructors throughout the codebase.


50-60: Resource constructors correctly updated to match new signatures.

Both NewLaunchResources and NewTestItemResources are now called with the simplified (client, analytics) signature, correctly reflecting the removal of the defaultProject parameter. The project value will now be determined dynamically from request parameters or context.

internal/reportportal/integration_project_test.go (2)

12-76: Well-structured integration tests validating new precedence rules.

The test cases comprehensively cover:

  • Request parameter precedence over HTTP header
  • Fallback to HTTP header when no request project (line 49-54) - important addition
  • Whitespace trimming for both sources
  • Error handling when no project is available

Test names are clear and accurately describe the expected behavior. Good coverage of the integration flow.


116-156: CompleteHTTPFlow test correctly validates request parameter precedence.

The test accurately simulates the complete HTTP flow and verifies that the request parameter ("request-project") takes precedence over the HTTP header ("header-project"). The updated comments clearly document the expected behavior, and the assertion properly validates the outcome.

internal/reportportal/items.go (1)

25-36: Constructor successfully refactored to remove defaultProject dependency.

The updated signature NewTestItemResources(client, analytics) removes the defaultProject parameter, and the project parameter is now defined generically via mcp.WithString. This shifts project determination to runtime extraction from request parameters or context, which aligns perfectly with the PR's objectives.

The implementation is clean and consistent with the pattern used in NewLaunchResources.

internal/reportportal/utils.go (1)

86-98: Excellent implementation addressing all previous review feedback!

The extractProject function now correctly implements the new precedence logic:

  1. Request parameter (with trimming) has highest priority
  2. Context-based project (HTTP header or environment) as fallback
  3. Clear error when no source provides a project

The comment on line 91 accurately describes the fallback behavior (addressing previous "First try" concern), and the error message on line 96 comprehensively mentions all three possible sources (request, HTTP header, environment variable). Well done!

internal/reportportal/http_server.go (1)

134-177: HTTP server resource initialization correctly updated.

The initializeTools function now properly calls NewLaunchResources and NewTestItemResources with the simplified (client, analytics) signature. The removal of the defaultProject parameter is consistently applied, and the HTTP server correctly relies on runtime project extraction from request parameters or context.

This completes the coordinated refactoring across the HTTP server implementation.

internal/reportportal/launches.go (1)

25-36: Project parameter precedence is correctly implemented.

The extractProject function properly implements the intended precedence order:

  1. Request parameter (with whitespace trimming via strings.TrimSpace)
  2. Context fallback via GetProjectFromContext(ctx)
  3. Descriptive error if neither is available

The absence of mcp.Required() on projectParameter is appropriate given this design—callers can omit the request parameter and it will be resolved from the HTTP header or environment. Error handling is clear and follows Go best practices.

Comment on lines +266 to +270
rpProject := cmd.String("project")
if rpProject != "" {
// Add project to request context default project name from Environment variable
ctx = mcpreportportal.WithProjectInContext(ctx, rpProject)
}
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Clarify the comment for accuracy.

The comment on line 268 states "Add project to request context default project name from Environment variable", but the code retrieves the project from the CLI flag (which may be sourced from RP_PROJECT via the Sources declaration on line 61). The comment is misleading about the direct source.

Apply this diff to improve clarity:

 	rpProject := cmd.String("project")
 	if rpProject != "" {
-		// Add project to request context default project name from Environment variable
+		// Add project to request context when provided via CLI flag
 		ctx = mcpreportportal.WithProjectInContext(ctx, rpProject)
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
rpProject := cmd.String("project")
if rpProject != "" {
// Add project to request context default project name from Environment variable
ctx = mcpreportportal.WithProjectInContext(ctx, rpProject)
}
rpProject := cmd.String("project")
if rpProject != "" {
// Add project to request context when provided via CLI flag
ctx = mcpreportportal.WithProjectInContext(ctx, rpProject)
}
🤖 Prompt for AI Agents
In cmd/reportportal-mcp-server/main.go around lines 266 to 270, the inline
comment incorrectly states the project name is coming from an environment
variable; update the comment to accurately state that the project value is taken
from the CLI flag (which may in turn originate from RP_PROJECT via the flag's
Sources configuration), e.g., "Add project from CLI flag (may be sourced from
RP_PROJECT) to request context" so it no longer implies a direct
environment-variable read.

@AleksandrParamonoff AleksandrParamonoff merged commit 433b5e1 into develop Oct 24, 2025
4 checks passed
@AleksandrParamonoff AleksandrParamonoff deleted the fix-required-flag-for-the-project-parameter branch October 24, 2025 11:05
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