Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

Summary

Makes owner_type optional in consolidated Projects V2 tools and fixes add_project_item to use explicit repository context instead of opaque IDs.

Why

Addresses two related issues:

  1. Users had to guess whether an owner was "user" or "org" when listing projects
  2. add_project_item accepted raw issue numbers without repository context, causing random external issues to be added to projects

Related: #1773, #1745

What changed

  • Made owner_type optional in projects_list, projects_get, and projects_write consolidated tools
  • Added automatic owner type detection (detectOwnerType helper)
  • Changed projects_list to fetch from both user and org when owner_type not specified:
    • Combines results with owner_type field on each project
    • Includes note about pagination limitations
  • Redesigned add_project_item in projects_write:
    • Now requires: item_owner, item_repo, issue_number/pull_request_number
    • Removed opaque item_id parameter
    • Uses GraphQL to resolve issue/PR numbers to node IDs internally
    • Uses addProjectV2ItemById mutation for accurate additions
  • Added OwnerType field to MinimalProject type
  • Added GraphQL resolution helpers: resolveIssueNodeID, resolvePullRequestNodeID

Individual tools unchanged (only consolidated tools modified per FeatureFlagConsolidatedProjects)

MCP impact

  • Tool schema or behavior changed
    • projects_list, projects_get, projects_write schemas updated
    • owner_type now optional (was required)
    • add_project_item parameters changed from item_id to item_owner/item_repo/issue_number/pull_request_number

Prompts tested (tool changes only)

Security / limits

  • No security or limits impact

Tool renaming

  • I am not renaming tools as part of this PR

Lint & tests

  • Linted locally with ./script/lint
  • Tested locally with ./script/test
  • Note: Marked old add_project_item tests with TODO (require GraphQL mocking)

Docs

  • Updated (README / docs / examples)
    • Auto-generated via script/generate-docs
Original prompt

Context

This PR addresses two related issues:

Core Problem

The GitHub MCP Server's Projects V2 tools are too reliant on opaque IDs (node IDs, numeric issue IDs without context) which causes:

  1. Trial-and-error patterns: Users must guess owner_type (user vs org) when listing projects
  2. Random issue additions: When adding items to projects using item_id, the tool uses raw issue numbers instead of resolving the full issue context (owner/repo/number), leading to random external issues being added

Design Philosophy

The MCP server should favor well-known values that models can guess correctly or intuit from training data over opaque IDs. If that means making 10 API calls internally to resolve identifiers, that's acceptable.

Required Changes

1. Remove owner_type requirement from project tools

Files to modify: pkg/tools/projects/ related files

  • Make owner_type optional in list_projects, list_project_fields, and similar tools
  • Implement automatic owner type detection: First try one type, if 404, try the other
  • Add a unified discovery tool that lists ALL accessible projects (personal AND organizational)
  • When a project URL or project number is provided, infer the owner context automatically

2. Fix add_project_item to use owner/repo/number instead of item_id

Files to modify: pkg/tools/projects/ related files

The current bug: add_project_item takes an item_id (issue number) without repository context, causing GitHub's API to add random issues.

Fix: Change the interface to accept:

  • owner (repository owner)
  • repo (repository name)
  • issue_number or pull_request_number (the human-readable number)

Then internally:

  1. Query GitHub to get the issue/PR's node ID:
query {
  repository(owner: "owner", name: "repo") {
    issue(number: 123) {
      id  # This is the node ID needed
    }
  }
}
  1. Use that node ID in the addProjectV2ItemById mutation

3. General principle: Replace all opaque IDs with well-known identifiers

For any tool accepting IDs:

  • Issues: Use owner, repo, issue_number (not node ID)
  • Pull Requests: Use owner, repo, pr_number (not node ID)
  • Projects: Use owner, project_number (not project ID)
  • Repositories: Use owner, repo (not node ID)

Implementation Notes

  • Look at existing patterns in pkg/tools/ for how other tools resolve identifiers
  • The GraphQL client is available for making resolution queries
  • It's fine to make multiple API calls internally to resolve identifiers
  • Maintain backward compatibility where possible by keeping old parameters as optional
  • Add clear documentation in tool descriptions about what values to provide

Testing

  • Ensure existing tests pass
  • Add tests for owner_type auto-detection
  • Add tests for issue resolution by owner/repo/number
  • Test both user and organization project scenarios

Related Code

  • Check pkg/tools/projects/ for existing project tools
  • Check internal/ for GraphQL client and API patterns
  • Look at how issue tools in pkg/tools/issues/ handle owner/repo/number patterns

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 12, 2026 20:51
…add_project_item

Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix owner type abstraction for ProjectV2 tools Make owner_type optional and fix add_project_item in consolidated Projects V2 tools Jan 12, 2026
Copilot AI requested a review from SamMorrowDrums January 12, 2026 20:56
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