WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilly-carrots-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ai-sdk/mcp': patch
---

fix(mcp): pass json header for refreshAuth
58 changes: 58 additions & 0 deletions examples/mcp/src/repro-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'dotenv/config';

const GITHUB_TOKEN_ENDPOINT = 'https://github.com/login/oauth/access_token';

async function testRefreshAuthorization() {
const clientId = process.env.GITHUB_CLIENT_ID;
const clientSecret = process.env.GITHUB_CLIENT_SECRET;
const refreshToken = process.env.GITHUB_REFRESH_TOKEN;

if (!clientId || !clientSecret || !refreshToken) {
throw new Error(
'Missing GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, or GITHUB_REFRESH_TOKEN',
);
}

const headers = new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
// Accept: 'application/json',
// UNCOMMENT ABOVE TO FIX
});

const params = new URLSearchParams({
grant_type: 'refresh_token',
refresh_token: refreshToken,
client_id: clientId,
client_secret: clientSecret,
});

const response = await fetch(GITHUB_TOKEN_ENDPOINT, {
method: 'POST',
headers,
body: params,
});

if (!response.ok) {
const errorText = await response.text();
throw new Error(`Token refresh failed: ${response.status} ${errorText}`);
}

const tokens = await response.json();

if (!tokens.access_token || !tokens.token_type) {
throw new Error('Invalid token response: missing required fields');
}

return tokens;
}

testRefreshAuthorization()
.then(() => {
console.log('====== Test passed ======');
process.exit(0);
})
.catch(error => {
console.log('====== Test failed ======');
console.error(error.message);
process.exit(1);
});
1 change: 1 addition & 0 deletions packages/mcp/src/tool/oauth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ describe('refreshAuthorization', () => {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
}),
}),
);
Expand Down
1 change: 1 addition & 0 deletions packages/mcp/src/tool/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ export async function refreshAuthorization(

const headers = new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
Accept: 'application/json',
});
const params = new URLSearchParams({
grant_type: grantType,
Expand Down
Loading