Pervasive Computing promotes an environment that blurs the distinction between digital and physical devices and integrates all entities in a physical space into a cohesive programmable unit. Some of the early research activities in pen-ash-e computing focused on de,eloping infrastructures for pervasive applications. These infrastructures successfully merged physical and digital entities in an environment to create aware homes, smart offices and active spaces. In recent years, ad-hoc pen,ash,e computing has attracted attention with the proliferation of low cost, short-range wireless devices. Ad-hoc pervasive computing does not assume digital de devices to be tied to physical environments and aims to create digital "clusters" that can be viewed as a unified entity. The user can program this cluster of devices with a single programming interface. In this paper, we introduce our middleware, called Mobile Gaia, for ad-hoc pervasive,e computing. Mobile Gaia is a servies-based middleware that integrates resources of various dei-ices. It manages several functions such as forming and maintaining device collections, sharing resources among dei-ices and enables seamless service interactions. It also provides an application framework to develop applications for the device collection. The application framework decomposes the application into smaller components that can run on different devices in this collection. We discuss the architecture of Mobile Gaia and introduce a sample application that has been designed using our middleware.